Consulting

Results 1 to 2 of 2

Thread: From main macro: Automatically Enable a macro when opening a file

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Location
    California
    Posts
    89
    Location

    Red face From main macro: Automatically Enable a macro when opening a file

    Hi,

    I am using the following code to open unknown files in a folder and process them.
    [vba]Sub OpenFiles()
    Const FOLDER_NAME As String = "C:\test\" '<===== change to suit
    Dim NextFile As String

    NextFile = Dir(FOLDER_NAME & "*.xls", vbNormal)
    Do While NextFile <> ""

    Workbooks.Open FOLDER_NAME & NextFile
    'do stuff on active workbook
    NextFile = Dir
    Loop
    End Sub [/vba]

    The files will have macros. How do I automatically enable the macro so the user doesn't have to take the time to click the enable macro button?

    Thanks

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi,

    Have you tried the code? I only have access to 2003, but since the user had to enable macs to open the file containing the code, the files opened programatically should not fire the alert/warning. I tested your code nearly as written and opened several excel files (that do contain code) and received no warnings.

    Mark

Posting Permissions

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