VBA Question

vandangosnr

New Member
Joined
Dec 6, 2005
Messages
22
I wonder if someone can help.
I'm running a spreadsheet in Excel 2003. What i want to do is transfer data via a macro to another workbook. At the moment I can do it but have to close the destination sheet after every transfer, becauase the macro i'm running opens the destination sheet every time. What i'm after is a bit of VBA code that will look to see if the destination sheet is open, then transfer in the data or if it is not open, open it and paste in my data.

I would be grateful to anyone who can shed some light on this for me.
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Fat Cat

Active Member
Joined
Nov 5, 2004
Messages
336
This bit of code (originally from Charllie) might do the trick;

Code:
isOpen = False

For Each wb In Workbooks                'check thru all open workbooks
   If wb.Name = "MyFile.xls" Then       'change to your file's name
      isOpen = True                           'your file is already
   End If
Next wb
                       
If isOpen = False Then
   Workbooks.Open Filename:="MyFile.xls"     'This opens your other workbook if it was closed
End If

Now you can Read/Write to the other workbook
 

vandangosnr

New Member
Joined
Dec 6, 2005
Messages
22
Thanks very much, thats been bugging me for ages.
Finally works how I originally wanted it to
 

Watch MrExcel Video

Forum statistics

Threads
1,118,521
Messages
5,572,627
Members
412,475
Latest member
JaredNAU
Top