Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timed macros running twice

Status
Not open for further replies.

Dezertdog

Technical User
Mar 4, 2017
2
US
Hello all,
I have been searching and am unable to find an answer to my problem.
I hope someone can help.
I have macros that run at certain times everyday. They run through Excel but perform a function in attachmate.
They work just fine... My problem is this:
If the Excel workbook the macros run from is open on another computer the macros will run twice. if open on 3 computers they run 3 times.
How can i prevent them from runing in all instances of Excel that are open?
One primary employee has the excel workbook open all day. but another might open it from time to time. if both are open at run time... both run the macro.
Any help will be greatly appreciated!

Scott
 
I would keep a log table that stores when the macro has been run. Then check this table prior to running.

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
 
You might also consider redesigning the Excel workbook system. Your users' workbooks would be a frontend to a backend workbook that would contain the data that your access macros tap and that would run your Attachmate screen scrape.

I'd also put a timer on the users' workbooks to save & close after x minutes of inactivity.



Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
dhookom & SkipVought,
Thank you for the quick reply and the ideas. However: your ideas led me in a completely new direction I hadn't considered...
It is one specific PC that the opener uses that will (or should) run my timed Macros. Any other Pc with the specific workbook open are secondary.
With that in mind I concluded I could ID that specific PC then run a check to see if that specific PC was running the workbook... If so, the Timed Macros would run.
I used...
CODE//
Dim PCName As String
PCName = Environ$("ComputerName")
Run MyOtherCode

'I ran the Macro with a message box to learn the PC's ID then put that data in Sheets("Data").Range("M21") and continued...

If PCName = Sheets("Data").Range("M21").Value Then

Application.OnTime TimeValue("06:30:00"), "Run_Ardaa"
Application.OnTime TimeValue("08:00:00"), "BreakTymes"
Application.OnTime TimeValue("10:00:00"), "LunchTyme"
Application.OnTime TimeValue("12:30:00"), "BreakTymes"
End If

CODE//
This worked beautifully for my configuration.

Problem solved.

Thank you again.

Dezertdog


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top