View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default EXCEL VBA question

Grace

I didn't answer your question because I believed it was the wrong solution
to a problem. What you want done is to copy from one place to another, not
to activate windows. So I still won't tell you, but see if this does what
you want:

Sub test()
Dim F As Variant
Dim wbSource As Workbook
Dim wbTarget As Workbook

Set wbTarget = ThisWorkbook 'or ActiveWorkbook
F = Application.GetOpenFilename("Workbooks (*.xls), *.xls", _
, "Select a file to copy into:")
If F = False Then Exit Sub
Set wbSource = Workbooks.Open(F)
wbSource.Sheets(1).Range("A1:F14").Copy wbTarget.Sheets(2).Range("D1:I14")
wbSource.Saved = True
wbSource.Close

End Sub

OR: Do you need to manually select a range in the middle of your macro ?

HTH. Best wishes Harald


"Grace" skrev i melding
...
Perhaps I am confused but I don't think you have answered my question.

What
I do is copy data from a source file to the same location in a destination
file. I do this for many different areas on many different tabs.

So, I go to the source file (which you have called F) and I highlight,

say,
worksheet tab 1, then a range of cells on that tab. Then I activate the
destination file, find the same tab and same cell area and paste it.

Then, I go back to the source file and repeat for another tab and area.

So,
each time I am toggling between two files. I was trying to find a way to
call the source file each time. I thought the command:

Windows(F.xls).Activate

would work but it bombs the macro out. What is the right syntax to toggle
back to that sheet?

Thanks,
Grace



"Harald Staff" wrote in message
...
"Grace" skrev i melding
...
I know that before
each copy operation, I don't want to re-open the file, but would

rather
activate it.


Usually one doesn't have to select or activate anything to move/copy

stuff
from one place to another. It just slows things down while looking ugly.

Best wishes Harald