Is it possible to pass arguments to a macro using "OnTime"?

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
Eg:

Code:
Sub Test()
 
b7 = ThisWorkbook.Path & ThisWorkbook.Name
 
Application.OnTime Now + TimeValue("00:00:02"), "Reopen(" & b7 & ")"
ThisWorkbook.Close SaveChanges:=True
 
End Sub
 
Public Function Reopen(Path, Workbook)
'==================================================
'Update 01: Reopens workbook after creation of new sheet
'Variable   Purpose
'i1         Workbook and Path
'==================================================
 
i1 = Path & Workbook
 
Workbooks.Open i1
 
End Function

This fails because the application looks for a macro named literally "Reopen(Workbook.Path & Workbook.Name)".

Is there a way to pass arguments to a macro using this method?
 
Glory,

Unless you absolutely need this to be fully automated , why not ask the user to check the security setting themselves at the start of your routine ?

Something along these lines to make life easier for them :

Code:
Sub Test()

    If Not TrustVBA Then
        With Application
        .SendKeys "t"
        .CommandBars.FindControl(id:=3627).Execute
        End With
    End If
    
    'rest of your code...
    
End Sub
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Jaafar: I only had to worry about using OnTime because of an OLE issue caused by trying to mess with VBA trust access settings.

I only had to mess with trust access because I needed to be able to insert code into a sheet.

I only needed to insert code into a new sheet because I had to make new buttons work (using a method I had found myself and could easily understand).

I only had to make new buttons work because new query tables named the same as old querytables which had already been deleted would have "_1" appended to the end of their name.

The only way to fix the problem with the new query tables was to delete and recreate the sheet, along with the buttons and the tables... which caused all of this.

I've fixed the root problem and all the rest went up like smoke.

http://www.mrexcel.com/forum/showthread.php?t=549541&page=2

Thanks for your help... both of you. I really appreciate the effort.
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

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