I ran into a strange problem, I decided to assign a keyboard shortcut Ctrl + Shift + P on one of my routine in VBA. This routine is suppose to open an existing excel workbook, copy some informations and .SaveAs another name.
This actually runs fine when I hit Play in the Visual Basic Editor. However, when I use the keyboard shortcut inside Excel to run my code, it stop working after opening the document.
I reproduce the problem in this sample:
Public Sub WriteData()
Dim templatePath As String
Dim templateWorkbook As Workbook
'it seems to hang on the following line
Set templateWorkbook = Application.Workbooks.Open(templatePath)
With templateWorkbook.Worksheets.Application
.Range("B3") = "Employee name"
.Range("B4") = "Employee first name"
.Range("B5") = "Employee email"
End With
templateWorkbook.SaveAs(ThisWorkbook.Path & "Test")
templateWorkbook.close
End Sub
I am using Excel 2007.