I'm running a look up function from the Ribbon *.xlam (file1) that opens a remote *.xlsm file containing all the project macros (file2), that in turn runs the lookup code on the remote database (file3).
File2 creates a variable "Confirm" string that works great when displayed as a Msgbox - but the msgbox is modal and stops the code. Meaning other users won't have write access to file3 while file2 is keeping it open.
To solve this, I created a Userform on file1 to mimic the msgbox in file2. Everything works and file2 and 3 are opened and closed as expected, but file2's variable "Confirm" is not passed through to File1's Userform label.
Condensed code below. Any help is greatly appreciated!
File1 *.xlam code:
Public Confirm As String
Sub ViewSUB(control As IRibbonControl)
Dim Sub_Macros As String, strFileExistsA As String, strFileExistsB As String
Dim currentWorkbook As Workbook
strFileExistsA = Dir(Sub_Macros_L)
strFileExistsB = Dir(Sub_Macros_R)
If strFileExistsA <> "" Then
Sub_Macros = Sub_Macros_L
ElseIf strFileExistsB <> "" Then
Sub_Macros = Sub_Macros_R
Else
MsgBox "Macro File is missing", vbCritical, "Macro File Missing"
Exit Sub
End If
Application.ScreenUpdating = False
Application.Calculation = xlManual
Set currentWorkbook = Application.ActiveWorkbook
Workbooks.Open Sub_Macros, ReadOnly:=True
currentWorkbook.Activate
Application.Run ("'Macros.xlsm'!ViewSUB")
ViewSub_Details.Show vbModeless
Workbooks("Macros.xlsm").Close SaveChanges:=False
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
File2 simply creates the string and I can prove it works with a msgbox. This is just a section of that code:
Public Confirm As String
For i = 3 To LastrowDBase
If DBase.Cells(i, 2) = SUBPN And DBase.Cells(i, 5) = "SomeText" Then
Confirm = Confirm & " - " & DBase.Cells(i, 3) & " - Flag: " & DBase.Cells(i, 7) & " - " & DBase.Cells(i, 6) & vbCrLf
End If
Next i
MsgBox Confirm
Then back at File1 the Userform code:
Option Explicit
Private Sub UserForm_Initialize()
Label1.Caption = Confirm
End Sub
Private Sub CommandButton01_Click()
Unload ViewSub_Details
End Sub
These quotes are from Excel help files