Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Navigate between 2 workbooks

I will have 2 workbooks open and wish to move backwards and forwards between
them.

One operation that needs to be carried out is to copy from one and paste to
the other and there may be other things as development progresses.

Just wondering what is the best method of reliably moving from one to the
other and back again?
--
Graham
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Navigate between 2 workbooks

Give yourself some variables to work with, helping to make it clear what you
are doing and avoiding the need for .Activate and/or .Select.

Dim SourceWB As Workbook
Dim DestinationWB As Workbook
Dim DestinationWS As Worksheet

Set SourceWB = Workbooks.Open(PathAndFileToSourceWB)
Set DestinationWB = Workbooks.Open(PathAndFileToDestinationWB)

With SourceWB
Set DestinationWS = DestinationWB.Worksheets("Destination1")
With .Worksheets("Source1")
.Range("A1").Copy Destination:=DestinationWS.Range("A1")
End With

With .Worksheets("Source2")
.Range("A1").Copy Destination:=DestinationWS.Range("A2")
End With

End With

NickHK

"Graham" wrote in message
...
I will have 2 workbooks open and wish to move backwards and forwards

between
them.

One operation that needs to be carried out is to copy from one and paste

to
the other and there may be other things as development progresses.

Just wondering what is the best method of reliably moving from one to the
other and back again?
--
Graham




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Navigate between 2 workbooks

Thanks Nick

I can see the logic in that.

But, the Destination WB will already be open as that will be the one with
the VBA code - will that make much difference?
--
Graham


"NickHK" wrote:

Give yourself some variables to work with, helping to make it clear what you
are doing and avoiding the need for .Activate and/or .Select.

Dim SourceWB As Workbook
Dim DestinationWB As Workbook
Dim DestinationWS As Worksheet

Set SourceWB = Workbooks.Open(PathAndFileToSourceWB)
Set DestinationWB = Workbooks.Open(PathAndFileToDestinationWB)

With SourceWB
Set DestinationWS = DestinationWB.Worksheets("Destination1")
With .Worksheets("Source1")
.Range("A1").Copy Destination:=DestinationWS.Range("A1")
End With

With .Worksheets("Source2")
.Range("A1").Copy Destination:=DestinationWS.Range("A2")
End With

End With

NickHK

"Graham" wrote in message
...
I will have 2 workbooks open and wish to move backwards and forwards

between
them.

One operation that needs to be carried out is to copy from one and paste

to
the other and there may be other things as development progresses.

Just wondering what is the best method of reliably moving from one to the
other and back again?
--
Graham





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Navigate between 2 workbooks

Graham,
OK, you can use ThisWorkbook
or
Set DestinationWB = ThisWorkbook
if your want be clear

NickHK

"Graham" wrote in message
...
Thanks Nick

I can see the logic in that.

But, the Destination WB will already be open as that will be the one with
the VBA code - will that make much difference?
--
Graham


"NickHK" wrote:

Give yourself some variables to work with, helping to make it clear what

you
are doing and avoiding the need for .Activate and/or .Select.

Dim SourceWB As Workbook
Dim DestinationWB As Workbook
Dim DestinationWS As Worksheet

Set SourceWB = Workbooks.Open(PathAndFileToSourceWB)
Set DestinationWB = Workbooks.Open(PathAndFileToDestinationWB)

With SourceWB
Set DestinationWS = DestinationWB.Worksheets("Destination1")
With .Worksheets("Source1")
.Range("A1").Copy Destination:=DestinationWS.Range("A1")
End With

With .Worksheets("Source2")
.Range("A1").Copy Destination:=DestinationWS.Range("A2")
End With

End With

NickHK

"Graham" wrote in message
...
I will have 2 workbooks open and wish to move backwards and forwards

between
them.

One operation that needs to be carried out is to copy from one and

paste
to
the other and there may be other things as development progresses.

Just wondering what is the best method of reliably moving from one to

the
other and back again?
--
Graham







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Navigate between 2 workbooks

Thanks Nick for yor prompt and clear help
--
Graham


"NickHK" wrote:

Graham,
OK, you can use ThisWorkbook
or
Set DestinationWB = ThisWorkbook
if your want be clear

NickHK

"Graham" wrote in message
...
Thanks Nick

I can see the logic in that.

But, the Destination WB will already be open as that will be the one with
the VBA code - will that make much difference?
--
Graham


"NickHK" wrote:

Give yourself some variables to work with, helping to make it clear what

you
are doing and avoiding the need for .Activate and/or .Select.

Dim SourceWB As Workbook
Dim DestinationWB As Workbook
Dim DestinationWS As Worksheet

Set SourceWB = Workbooks.Open(PathAndFileToSourceWB)
Set DestinationWB = Workbooks.Open(PathAndFileToDestinationWB)

With SourceWB
Set DestinationWS = DestinationWB.Worksheets("Destination1")
With .Worksheets("Source1")
.Range("A1").Copy Destination:=DestinationWS.Range("A1")
End With

With .Worksheets("Source2")
.Range("A1").Copy Destination:=DestinationWS.Range("A2")
End With

End With

NickHK

"Graham" wrote in message
...
I will have 2 workbooks open and wish to move backwards and forwards
between
them.

One operation that needs to be carried out is to copy from one and

paste
to
the other and there may be other things as development progresses.

Just wondering what is the best method of reliably moving from one to

the
other and back again?
--
Graham









Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Navigate between open workbooks Corey Excel Programming 2 November 2nd 06 09:16 AM
Navigate between worksheets Louise Excel Worksheet Functions 1 October 9th 06 05:27 PM
Navigate Sheets - better way. Doug929 Excel Programming 2 August 29th 05 03:06 PM
Navigate by macro Bob Phillips[_6_] Excel Programming 0 May 28th 04 04:39 PM
Navigate by macro Frank Kabel Excel Programming 2 May 28th 04 04:38 PM


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"