Results 1 to 5 of 5
  1. #1
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34

    Edit a publisher text box with VBA?

    I'm currently using the following to edit a publisher document using access VBA.

    Code:
     For Each pubShape In pubDoc.Pages(1).Shapes
        If pubShape.HasTextFrame Then
            If pubShape.Name = "Text Box 440" Then pubShape.TextFrame.TextRange.Text = Item1
            If pubShape.Name = "Text Box 441" Then pubShape.TextFrame.TextRange.Text = Item2
            If pubShape.Name = "Text Box 442" Then pubShape.TextFrame.TextRange.Text = Item3
            If pubShape.Name = "Text Box 443" Then pubShape.TextFrame.TextRange.Text = Item4
            If pubShape.Name = "Text Box 444" Then pubShape.TextFrame.TextRange.Text = Item5
            If pubShape.Name = "Text Box 445" Then pubShape.TextFrame.TextRange.Text = Item6
            If pubShape.Name = "Text Box 446" Then pubShape.TextFrame.TextRange.Text = Item7
            If pubShape.Name = "Text Box 447" Then pubShape.TextFrame.TextRange.Text = Item8
        End If
    Next
    



    Obviously there are a lot of shapes/boxes etc in the document and this code is very inefficient and takes a few moments to complete. Is there a way to directly reference a text box and change its value. For word I have been using bookmarks but this doesn’t seem to work with publisher.

    I’m looking for something like pubshape.Value(“text Box 440”) = Item1 but cannot find the correct syntax.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Are you trying to do this from within an MS Access database?
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Yes. I'm using vba in an access form. I want to add data to a publisher file, save it as pdf and then reopen it. It works fine but takes a while as it cycles through every shape in the publisher document and there are quite a lot. I just want to put data in the required shapes (text boxes) directly but don't know how to reference them with vba code.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Best I can find so far http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    "... if the value of the Name property for a shape is Rectangle 2, then .Shapes("Rectangle 2") will return a reference to that shape."
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Thank you. That was just the push I needed. I now have:

    Code:
    pubDoc.Pages(1).Shapes("Text Box 440").TextFrame.TextRange.Text = Item1
    and it works fine.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-05-2014, 09:29 AM
  2. Replies: 9
    Last Post: 02-26-2013, 10:48 AM
  3. Replies: 14
    Last Post: 12-26-2011, 07:32 PM
  4. Trusted Publisher
    By rovman in forum Access
    Replies: 1
    Last Post: 10-22-2011, 02:55 PM
  5. Edit Buttons for a Rich Text Box on Form
    By trb5016 in forum Forms
    Replies: 2
    Last Post: 10-13-2010, 12:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums