Consulting

Results 1 to 4 of 4

Thread: My greeting macro doesn't run automatically when I open Excel

  1. #1

    Exclamation My greeting macro doesn't run automatically when I open Excel

    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
    Attached Images Attached Images

  2. #2
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    2
    Location
    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!

  3. #3
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    2
    Location
    Also, for pasting the code you should use the code tag. Click on the little hash/pound/number sign in the edit box.

    Cheers!

  4. #4
    Thank you very much. It works!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •