user1904295
user1904295

Reputation: 31

Run macro in background

I have some trouble with VBA macros.

  1. While opening a Excel file (FILE1.xls) which has a macro (the macro contains a userform with command buttons which i programmed it to use those command buttons as shortcuts to folders, website etc...). There is no problem with this step.

  2. I am trying to open a new Excel file (FILE2.xls) without macro (for example a file i received by mail) when I open the file it's invisible. I think it's a problem coming from my macro.

So I want to run this macro in background and be able to open 6 different Excel files (for example).

I have been searching to solve this problem for a long time.

Upvotes: 3

Views: 9297

Answers (2)

Christoph Hauser
Christoph Hauser

Reputation: 43

I have used the below function to open several workbooks in the background.

Example call:

Set newWorkbook = GetWorkbook(scoreCardLink)

Function:

Public Function GetWorkbook(fullFileName As String) As Workbook
Application.ScreenUpdating = False
Dim result As Workbook
Dim sFileName As String
On Error Resume Next

strFilePath = fullFileName
vParts = Split(strFilePath, "/")
sFileName = vParts(UBound(vParts))

Set result = Workbooks(sFileName)
If (result Is Nothing) Then
    Application.enableEvents = False
    Set result = Workbooks.Open(fullFileName, ReadOnly = True, IgnoreReadOnlyRecommend = False)
End If
Set GetWorkbook = result
End Function

Upvotes: 1

Alex K.
Alex K.

Reputation: 175766

You can set the UserForms ShowModal property to False in its properties window to prevent it blocking.

Upvotes: 2

Related Questions