Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Documents with embedded code (VBE/Word/2000)

    Note: The above should read VBA not VBE The author can't type!

    The following snippet of code is part of a larger package, but contains all that is exercised in my problem.
    The code I am trying to run is in the Normal template
    I have 15 or so files in a given folder and open them all simultaneously with Windows explorer.
    One of the files has an embedded macro.
    When I run the macro shown here after opening the 15 documents and clicking "Disable Macros" during the opening process; the macro terminates without dialogue when myDoc becomes the document with the embedded macro. This happens only on the first instance of running ID_No_Change_Bars. The second time it is run, the code runs to completion.
    I can't see how it would make a difference, but when calling the macro, the document containing a macro was not the active document.
    Can someone offer me sufficient insight that I can get the process to run to completion irrespective of how the user has opened the files even if he has elected to disable the macros in a given file?

    TIA

    <pre>Option Explicit
    Const ID_Style = "[ID#]"


    Public Sub ID_No_Change_Bars()
    Dim abort As Boolean
    abort = False
    Call Initialize(abort)
    Debug.Print "Exit 4"
    If abort Then Exit Sub
    Call ProcessTemp
    Call ProcessFinal

    End Sub

    Public Sub Initialize(abort As Boolean)

    Dim ctr As Byte
    Dim msg As String
    Dim msgResp As Byte
    Dim myDocArray As Variant
    Dim myDoc As Document
    Dim myPath As String
    Dim myTitle As String
    Dim Resp As Variant
    ReDim myDocArray(0)
    Debug.Print "init"
    abort = False
    myTitle = "Removing ""Change Bars"" from the ""ID#"" Paragraphs"

    Debug.Print "Test Point"
    For Each myDoc In Documents
    Debug.Print myDoc.Name
    If UCase(myDoc.Name) = "TEMP.DOC" Or UCase(myDoc.Name) = "FINAL.DOC" Then
    msg = myDoc.Name & " must be closed before this macro can run." _
    & vbCrLf & vbCrLf
    msg = msg & "Do you wish to save " & myDoc.Name & vbCrLf
    msg = msg & "before it is closed? ""Yes/No""" & vbCrLf & vbCrLf
    msg = msg & "To abort the process, click ""Cancel"""
    msgResp = MsgBox(msg, vbExclamation + vbYesNoCancel, myTitle)
    If msgResp = 2 Then ' Cancel
    abort = True
    Debug.Print "Exit 1"
    Exit Sub
    ElseIf msgResp = 6 Then ' yes
    myDoc.Save
    End If
    myDoc.Close wdDoNotSaveChanges
    End If
    Next

    End Sub
    </pre>

    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Documents with embedded code (VBE/Word/2000)

    I tried to reconstruct your situation (copied the code into a module, opened a bunch of documents from Explorer, one of which contains macros, disabled macros in this document, ran the ID_No_Change_Bars macro), but the macro runs to completion each time (I quit and restarted Word in between runs). So no idea, sorry.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Documents with embedded code (VBE/Word/2000)

    Thanks Hans
    If I ever do resolve this I will post the solution here.
    Regards
    Don

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Documents with embedded code (VBE/Word/2000)

    I reasoned that since "The second time it is run, the code runs to completion.", running any code might do the trick. Consequently I placed a new procedure within the module.

    <font color=blue> Public Sub AutoOpen()

    End Sub</font color=blue>


    By golly! it cured the problem. Please don't ask me why.
    Regards
    Don

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Documents with embedded code (VBE/Word/2000)

    At least, it's a workaround. Apparently, it's not needed in Office XP.

Posting Permissions

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