Quick question about VB Word macros

This is a discussion on Quick question about VB Word macros within the Tech Board forums, part of the Community Boards category; Anyone familiar with using VB for Word macros? I'm looking for a quick down and dirty macro that does the ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Quick question about VB Word macros

    Anyone familiar with using VB for Word macros? I'm looking for a quick down and dirty macro that does the following steps in order when run:

    -Saves the file
    -Deletes current footer
    -Makes a new footer that displays the current file name, right adjusted
    -Resaves the file

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    Sub PJYelton()
        Dim FileName As String
        With ActiveDocument
            .Save
            FileName = .Name
            With .Sections(1).Footers(wdHeaderFooterPrimary).Range
                .Text = FileName
                .ParagraphFormat.Alignment = wdAlignParagraphRight
            End With
            .Save
        End With
    End Sub
    Moved to tech board

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks, that works perfectly! Sorry about the wrong forum, I debated which one it was best to put it in.

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Sorry to rehash an old thread but a small problem has come up with this macro. If the document has no name then it uses SaveAs which is great, but if the user clicks cancel then theres a runtime error. What is the easiest way around this?

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Quote Originally Posted by PJYelton
    Sorry to rehash an old thread but a small problem has come up with this macro. If the document has no name then it uses SaveAs which is great, but if the user clicks cancel then theres a runtime error. What is the easiest way around this?
    Code:
    Sub PJYelton()
    On Error Resume Next
        Dim FileName As String
        With ActiveDocument
            .Save
            FileName = .Name
            With .Sections(1).Footers(wdHeaderFooterPrimary).Range
                .Text = FileName
                .ParagraphFormat.Alignment = wdAlignParagraphRight
            End With
            .Save
        End With
    End Sub

  6. #6
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks!

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    Just a question, why do you need to save before and after?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about macros
    By lazyme in forum C++ Programming
    Replies: 19
    Last Post: 04-27-2009, 10:10 PM
  2. Quick question about types...
    By Elysia in forum C++ Programming
    Replies: 32
    Last Post: 12-07-2008, 04:39 AM
  3. Quick question on malloc and strings
    By officedog in forum C Programming
    Replies: 20
    Last Post: 11-06-2008, 04:14 PM
  4. Quick question
    By Rapt in forum C Programming
    Replies: 5
    Last Post: 11-01-2003, 01:16 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21