set vba to interact with set instance of excel

dantheman9

Board Regular
Joined
Feb 5, 2011
Messages
175
My code runs fine, in terms of an automatic update on time every xx minutes or so, the problem is, if I have two excel windows opens, it copies data to which ever on is selected at the time of the update. I there a way to tie code to the instance of excel that is selected at the time of launching the code?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
It sounds like your routine uses unqualified references.
Use syntax like
Code:
Workbooks("Workbook1.xls").Sheets("Sheet1").Range("A1").Value = 3
rather than
Code:
Range("A1").Value = 3
 
Upvote 0
Hi Mike,

thanks for getting back yes it does at present, would it work in terms of setting the workbook name as a varaible? (So the vba code is all on a userform, which is activated by an open/close option in excels ribbon).
Something like

Code:
Public Name as Workbook
 
Sub open ()
 
Set Name as Active Workbook
 
blah
blah
End Sub
 
Upvote 0
Something like

Code:
Dim myWorkbook as Workbook

Set myWorkbook = ActiveWorkbook

myWorkbook.Sheets("Sheet1").Range("A1") = 3
or perhaps

Code:
Dim myWorksheet as Worksheet

Set myWorksheet = ActiveSheet

myWorksheet.Range("A1") = 3

If the download always goes to the same workbook that holds the code for the UF, you could use ThisWorkbook rather than ActiveWorkbook.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top