PDA

View Full Version : My greeting macro doesn't run automatically when I open Excel



genevievebr0
08-06-2014, 08:06 AM
Hi,
I am very new to VBA coding. This stuff is usually left to my colleague but he is on vacation. I copied the greeting macro from another of his Excel files. It runs perfectly when I open the Visual basic. However, it doesn't run automatically when I open the document. Could somebody please help me, I am desperate.

Here's the code :

Private Sub Greeting()
' Will run automatically when the workbook is opened.

Dim ws As Worksheet
Dim Msg As String
Dim Style As Long
Dim Title As String
Dim Response As Long
Dim i As Long
Dim wb As Workbook

Application.Run "Workbook_Open"
Application.Run "ProtectSheets"
MsgBox ("Le classeur Excel est prêt à l'emploi." & Chr(10) & "The Excel workbook is ready for use.")
End Sub

Also, is there a way to copy and paste the VBA code in the forum without having to change color manually?

Thank you very much!!!!
geneviève

Jseph
08-06-2014, 08:39 AM
Howdy,

Generally if you want to get code to run when the workbook is open, put it in the Workbook_Open sub. This sub needs to be in the ThisWorkbook page in the VBA editor. Try moving your code there.

Example:


Private Sub Workbook_Open()
'put your code here
End Sub


Cheers!

Jseph
08-06-2014, 08:44 AM
Also, for pasting the code you should use the code tag. Click on the little hash/pound/number sign in the edit box.

Cheers!

genevievebr0
08-06-2014, 10:56 AM
Thank you very much. It works!!!!