Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBE Tips'n'Tricks - GoTo

    What's your favorite trick in using VBE? I'm working mainly in Word97SR2 VBE, and I understand that VBE varies from desktop application to desktop application.



    Using a syntax error as a place marker.
    =======================================


    I like to keep my source code syntax-free. I frequently issue a Debug,Compile to check that at least my typing is OK (As some of you now know, I'm a LOUSY triper). This gives me a useful equivalent of the Shift-F5 trick in Word.

    I need to go somewhere else, but also need to return here. I type some gibberish right where I need to return, almost any stab at the keyboard will do, such as "k,hg" or ",jhbglj" or even "setbaserg" (each time without the quotes)

    I go somehwre else, and then issue a Debug,Compile to return me to wherever I was before. Bonus: the offending code is highlit, and I can paste new code (Ctrl-V) right on top of it.

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    Chris,

    You can use the same thing using bookmarks- although these only live in the current session.

    In the edit toolbar, thares a button with a blue flag. Position yourself to the first line, and press the flag icon. When you want to return, press one of the icons with a flag and arrow. You can remove one bookmark by pressing the flag icon when you're on that line again, or remove all with the flag and cross icon.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    Here's some code to open your current project after opening the file: (I click a toolbar button to execute)

    <pre>Sub OpenProject()
    Documents.Open ThisDocument.FullName
    Application.ShowVisualBasicEditor = True
    Application.VBE.VBProjects("ProjectNameHere").VBCo mponents(2).Activate
    End Sub
    </pre>


    This could probably be a bit more automated, but it saves a few keystrokes.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    That's a clever idea and I might give that a try, but I guess I'm with Geoff. Why not just use the bookmark buttons?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    Good one. I'd not read as far as the Edit toolbar yet. Got any more?

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    OK. I pasted and ran it in Word97/SR2.

    It opened the VBE, which I like, but what is the significance of the (2). Will that 2nd component always be the same?

    I tried to obtain an open-vbe-and-maximize some months ago but never quite got the hang of it. I'd like to have something in an Auto macro that recognised I was opening a template, and opened up the VBA to the max as it ran.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    If the project is not password protected, the (2) opens the first module in the Module folder -- it works for me...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    See? I know more since joining Woody's lounge than I did before I joined.

    I now have a crude but effective AutoExec macro in my protected N20000530.dot which gets copied to Normal.dot whenever I fire up Word97.

    The AutoExec (Thanks Kevin!!) opens AND MAXIMIZES my VBE window.

    That saves me from Alt-T,M,V; Alt-space,X each time I open Word.



    <pre>Sub autoexec()
    Documents.Open ThisDocument.FullName
    Application.ShowVisualBasicEditor = True
    Application.VBE.VBProjects("CG").VBComponents(2).A ctivate
    Application.VBE.MainWindow.WindowState = 2
    End Sub
    </pre>




    (later)

    I got even smarter and change dit from an AutoExec to a regular command macro (cmd_VBE) and attached it to a button on my toolbar. Now I don't have to wait whil all my templates open (we had that 256-template experiment a few weeks ago) when i just want to draft a memo to the local church.

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBE Tips'n'Tricks - GoTo

    Hey, man...


    You're welcome.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word97SR2: bypass the macro security check

    <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/newreply.pl?Cat=&Board=vb&Number=21172&page=&view= &what=showflat&sb=&part=1&vc=1>Kevin's Post</A>

    My VBE-opener has crept on apaste. The current version is pasted below .

    I assign the cmd_VBE to a toolbar button on the Standard toolbar in my Normal.dot. Shame!


    It works well. Typically I fire up Word to start work on a template, click on the toolbar button and browse to today's template. Whoop-de-doo!


    However I noticed today that this method appears to bypass the macro security check (Word97SR2). After opening a template, I Alt-Tab back to Word, check the settings of Tools, Options. Good. Open another template (File, Open) and get the Enable/Disable/doNotOpen message, so all that stuff is still in place.

    <pre>Sub cmd_VBE()
    ' Procedure : cmd_VBE
    ' Description: Open/Maximize the VBE; open a document/template.
    ' By: Chris Greaves With GREAT help from Kevin Paddock .
    ' Inputs: None
    ' Returns: None.
    ' Assumes: None.
    ' Side Effects: Appears to bypass the macro-security check.
    ' Tested: By the calls below.


    Dim strName As String ' Retain filename/extent from dialogue box.
    With Dialogs(wdDialogFileOpen)
    .Name = "*.dot" ' Specifically interested in templates, since we're opeing VBE
    .Show
    strName = .Name ' Grab the Name; user will have navigated to DefaultFilePath.
    End With
    Documents.Open FileName:=Options.DefaultFilePath(wdDocumentsPath) _
    & Application.PathSeparator & strName
    Application.ShowVisualBasicEditor = True ' Open VBE
    Application.VBE.MainWindow.WindowState = 2 ' same as vbext_ws_Maxz
    End Sub
    </pre>


  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word97SR2: bypass the macro security check

    Chris,

    I'm glad I am so helpful, but you give me too much credit. Keep up the good work!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word97SR2: bypass the macro security check

    > Keep up the good work!


    OK Boss.



    I still don't understand dialogue boxes.

    I have upgraded my VBE-opener yet again, this time I've dropped in "On Error" (which I hate) as a temporary measure to get around what happens when the user (moi) uses the Cancel button in the Documents.Open dialogue box.

    I'd appreciate some help in understanding how to obtain both the value of the key pressed (cancel) and the Path/name of the file if OK is chosen, all in one fell swoop.

    I feel that I shouldn't have to resort to an ON ERROR for an event that I can anticipate.

    <pre>Sub cmd_VBE()
    ' Procedure : cmd_VBE
    ' Description: Open/Maximize the VBE; open a document/template.
    ' By: Chris Greaves With GREAT help from Kevin Paddock .
    ' Inputs: None
    ' Returns: None.
    ' Assumes: None.
    ' Side Effects: Appears to bypass the macro-security check.
    ' Tested: By the calls below.


    Dim strName As String ' Retain filename/extent from dialogue box.
    With Dialogs(wdDialogFileOpen)
    .Name = "*.dot" ' Specifically interested in templates, since we're opeing VBE
    .Show
    strName = .Name ' Grab the Name; user will have navigated to DefaultFilePath.
    End With
    On Error GoTo Cancelled
    Documents.Open FileName:=Options.DefaultFilePath(wdDocumentsPath) _
    & Application.PathSeparator & strName
    Cancelled:
    On Error GoTo 0
    Application.ShowVisualBasicEditor = True ' Open VBE
    Application.VBE.MainWindow.WindowState = 2 ' same as vbext_ws_Maxz
    End Sub


    </pre>


  13. #13
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word97SR2: bypass the macro security check

    Chris,

    The following bit is from the MS Word VBA help on dialog boxes:

    <hr>
    Checking how a dialog box was closed

    The value returned by the Show and Display methods indicates which button was clicked to close the dialog box. The following example displays the Break dialog box, and if OK is clicked, a message is displayed on the status bar.

    If Dialogs(wdDialogInsertBreak).Show = -1 Then
    StatusBar = "Break inserted"
    End If
    Return value Description
    -2 The Close button.
    -1 The OK button.
    0 (zero) The Cancel button.
    > 0 (zero) A command button: 1 is the first button, 2 is the second button, and so on.
    <hr>

    As to getting values, I quote again:

    <hr>
    Many of the built-in Word dialog boxes have arguments that you can use to set or get values from a dialog box (for example, RightIndent in the previous example). To determine which arguments you can use, see Built-in dialog box argument lists.
    <hr>

    Looking in the "Built-in dialog box argument lists" help, I see:

    <hr>
    wdDialogFileOpen

    Name, ConfirmConversions, ReadOnly, LinkToSource, AddToMru, PasswordDoc, PasswordDot, Revert, WritePasswordDoc, WritePasswordDot, Connection, SQLStatement, SQLStatement1, Format, Encoding, Visible
    <hr>

    so we could code this to do what you want:
    <pre>With Dialogs(wdDialogFileOpen)
    If .Show = -1 Then
    MsgBox (.Name)
    End If
    End With
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word97SR2: bypass the macro security check

    Thanks Kevin, Geoff (this is getting out of hand).

    Here's the final version. No, Honest!

    <pre>
    Sub cmd_VBE()
    ' Procedure : cmd_VBE
    ' Description: Open/Maximize the VBE; open a document/template.
    ' By: Chris Greaves With GREAT help from Kevin Paddock and Geoff Whitfield .
    ' Inputs: None
    ' Returns: None.
    ' Assumes: None.
    ' Side Effects: Appears to bypass the macro-security check.
    ' Tested: By the calls below.


    Dim strName As String ' Retain filename/extent from dialogue box.
    With Dialogs(wdDialogFileOpen)
    .Name = "*.dot" ' Specifically interested in templates, since we're opeing VBE
    If .Show = -1 Then
    strName = .Name ' Grab the Name; user will have navigated to DefaultFilePath.
    Documents.Open FileName:=Options.DefaultFilePath(wdDocumentsPath) _
    & Application.PathSeparator & strName
    Else
    End If
    End With
    Application.ShowVisualBasicEditor = True ' Open VBE
    Application.VBE.MainWindow.WindowState = 2 ' same as vbext_ws_Maxz
    End Sub
    </pre>




    You'll recall that I copy N20000530.dot over Normal.dot as part of firing up Word. So here I am in Word editing cmd_VBE in a transient Normal.dot. It appears to work, so it's time to paste it into my secure N200005630.dot. I select all the code, then RUN THE CODE to bring up the Open dialogue to navigate to the secure template ....

    Man! Was THAT ever keen!

  15. #15
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Word97SR2: bypass the macro security check

    Hi Chris, Kevin:

    Here's amended code that demonstrates how to return the button the user clicks on when you display a built-in dialog:

    <pre>Sub TestDialogReturn()
    Dim strName As String ' Retain filename/extent from dialogue box.
    With Dialogs(wdDialogFileOpen)
    .Name = "*.dot" ' Specifically interested in templates, since we're opeing VBE
    If .Show <> -1 Then
    Exit Sub
    Else
    strName = .Name ' Grab the Name; user will have navigated to DefaultFilePath.
    End If
    End With
    Documents.Open FileName:=Options.DefaultFilePath(wdDocumentsPath) _
    & Application.PathSeparator & strName
    End Sub
    </pre>

    Fuller details can be found in Word VBA Help under "Displaying built-in Word dialog boxes"

    Gary


    *** edited Geoff W Long lines in "pre" tag shortened ***

Page 1 of 3 123 LastLast

Posting Permissions

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