S
Sean
I have received the following code from this WG, which places code
within ThisWorkbook, problem is I'm receiving a syntax error on both
message 1 & 2 and I'm just about lost at this stage of where I'm gone
wrong, any help appreciated
Sub Populate_TW()
Dim StartLine As Long
Dim msg1 As String, msg2 As String
Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
msg1 = "Dim myArray As Variant" & vbCr & _
"Dim arName As String" & vbCr & _
"Dim ws As Worksheet" & vbCr & _
"arName = ""MyUsers"" & vbCr & _
"myArray = ThisWorkbook.Names(arName).RefersToRange.Value"
msg2 = "With Application"& vbCr & _
"If IsError(.WorksheetFunction.Match(.UserName, myArray, 0)) Then " &
vbCr & _
"MsgBox ""You are NOT Permitted to access this File "" & vbCr & _" &
vbCr & _
""""" & vbCr & _" & vbCr & _
"""Please Contact Joe Bloggs at "" & vbCr & _" & vbCr & _
""""" & vbCr & _" & vbCr & _
"""ABC Group +9842 45 852462000""" & vbCr & _
"Application.DisplayAlerts = False" & vbCr & _
"ThisWorkbook.Close False" & vbCr & _
"Else" & vbCr & _
"For Each ws In Worksheets" & vbCr & _
"ws.Visible = True" & vbCr & _
"Next" & vbCr & _
"Worksheets("Splash").Visible = False" & vbCr & _
"Worksheets("Users").Visible = False" & vbCr & _
"Worksheets("info").Activate"& vbCr & _
"Application.DisplayAlerts = True" & vbCr & _
"End If"& vbCr & _
"End With"
With ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
StartLine = .CreateEventProc("Open", "Workbook") + 1
..InsertLines StartLine, msg1 & vbCr & msg2
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub
within ThisWorkbook, problem is I'm receiving a syntax error on both
message 1 & 2 and I'm just about lost at this stage of where I'm gone
wrong, any help appreciated
Sub Populate_TW()
Dim StartLine As Long
Dim msg1 As String, msg2 As String
Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
msg1 = "Dim myArray As Variant" & vbCr & _
"Dim arName As String" & vbCr & _
"Dim ws As Worksheet" & vbCr & _
"arName = ""MyUsers"" & vbCr & _
"myArray = ThisWorkbook.Names(arName).RefersToRange.Value"
msg2 = "With Application"& vbCr & _
"If IsError(.WorksheetFunction.Match(.UserName, myArray, 0)) Then " &
vbCr & _
"MsgBox ""You are NOT Permitted to access this File "" & vbCr & _" &
vbCr & _
""""" & vbCr & _" & vbCr & _
"""Please Contact Joe Bloggs at "" & vbCr & _" & vbCr & _
""""" & vbCr & _" & vbCr & _
"""ABC Group +9842 45 852462000""" & vbCr & _
"Application.DisplayAlerts = False" & vbCr & _
"ThisWorkbook.Close False" & vbCr & _
"Else" & vbCr & _
"For Each ws In Worksheets" & vbCr & _
"ws.Visible = True" & vbCr & _
"Next" & vbCr & _
"Worksheets("Splash").Visible = False" & vbCr & _
"Worksheets("Users").Visible = False" & vbCr & _
"Worksheets("info").Activate"& vbCr & _
"Application.DisplayAlerts = True" & vbCr & _
"End If"& vbCr & _
"End With"
With ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
StartLine = .CreateEventProc("Open", "Workbook") + 1
..InsertLines StartLine, msg1 & vbCr & msg2
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub