1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

MS Word 2010 AutoOpen Macro to Insert Date into Text Boxes

Discussion in 'Software Development' started by LukeB12345, Jul 3, 2013.

Thread Status:
Not open for further replies.
  1. LukeB12345

    LukeB12345 Thread Starter

    Jul 3, 2013
    I am trying to create an AutoOpen VBA Macro in Word 2010 files for automatically inserting the same dates into 2 different text boxes when I first open the file. Ideally, I would want 1 file to do this always for Yesterday's date (whatever that may be) and another file to do this for Friday's date (whatever that may be).

    Reason for this is because our mail room gets mail the day before I get it on my desk and I need to date stamp it using a Word 2010 template where I have 2 text boxes (please see attached file--oh, doesn't seem like I can attach the file???) for Tuesday through Friday. Right now, I am using the Macros I have created (1 for Yesterday's Date and another Macro for Friday's Date which is Date() -3).

    I want to use that Macro logic to put that into the Text boxes I have when it first opens? Please help me with this anyone......

    It doesn't seem like I can attach the file so here is the VBA code:

    Sub AutoOpen()
    ' AutoOpen Macro that places the cursor at the last position of edit (not default of top left) (will work with Protected View)
    If Application.ActiveProtectedViewWindow Is Nothing Then
    End If

    ' InsertTextBox1 Macro
    Dim Shp As Shape
    Set Shp = ActiveDocument.Shapes.AddTextbox( _
    Orientation:=msoTextOrientationVertical, _
    Left:=22, Top:=252, Width:=25, Height:=170)
    Shp.TextFrame.TextRange.Text = "NMM RECEIVED: "
    Set Shp = Nothing
    Selection.InsertAfter Format(Now() - 1, "dddd, MMMM dd, yyyy")
    Selection.Font.Size = 8
    Selection.Font.Name = "Arial Narrow"
    Selection.Font.Bold = wdToggle
    Selection.Font.Bold = wdToggle

    ' InsertTextBox1 Macro
    Dim Shp2 As Shape
    Set Shp2 = ActiveDocument.Shapes.AddTextbox( _
    Orientation:=msoTextOrientationHorizontal, _
    Left:=432, Top:=752, Width:=170, Height:=18)
    Shp2.TextFrame.TextRange.Text = "NMM RECEIVED: "
    Set Shp2 = Nothing
    End Sub

    Thank you in advance,
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1102705

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice