+ Reply to Thread
Results 1 to 14 of 14

Excel VBA to Update Word InlineShapes using Previous Heading Text

  1. #1
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Excel VBA to Update Word InlineShapes using Previous Heading Text

    My question is how do I get the previous Heading text from above the InlineShape and use it to update the Alternative Text in the InlineShape?

    Here's the Word doc layout:

    New Page -

    Heading

    InlineShape

    Heading

    InlineShape


    New Page -

    Heading

    InlineShape

    Heading

    InlineShape

    etc.
    etc.

    Here's a code snippet:
    Please Login or Register  to view this content.
    Last edited by pmrsed; 12-20-2020 at 11:39 PM.

  2. #2
    Forum Contributor
    Join Date
    12-08-2020
    Location
    South Korea
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    could you attached sample MS Word file? It could be more easier to help for you.
    Does the VBA Code run from MS Excel to Word? or...Run into Word itself?
    Last edited by chronjy; 12-20-2020 at 11:59 PM.

  3. #3
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    It is run from Excel VBA to Word and opens specified Word documents. Then the code locates InlineShapes in Word and attempts to get the heading above the shape and use its text to update the Shapes' Alternative Text. The routine I'm missing is: Call GetPrevHeadingLevel

    This attempt here (code below) actually uses the InlineShape page number and matches it with the TOC page number. When they are equal I grab the TOC text for that page number and slap it on the Alt Text for the InlineShape. And it works. The problem is there isn't any consistency in how the Word doc's are laid out when it comes to Headings. In other words, some pages may have 2 or more InlineShapes with only one Heading 1 above. It's not a one-to-one where each InlineShape has it's own Heading. If that were the case I could go with this approach.

    The most sure fire approach is to locate the Inlineshape first (which I have) ; and then get the first previous Heading from above. That would solve my problems.

    It seems really like I'm asking a very basic EXCEL question but I'm not getting a response on ANY message board. I'm certain that I'm missing a very basic principle or fundamental feature in Excel VBA that moves you to the previous Heading from a location (InlineShape) you're already at. I'm asking how do you get from point A to point B on the SAME page and no one has been able to tell me how to do it.

    Oh, BTW if you haven't already guessed I'm not Steve McQueen Macro Man. I'm a learning hack like a lot of folks out there and most of my learning has been taking over maintenance of such doc's and tech sites like this one.


    Please Login or Register  to view this content.
    Last edited by pmrsed; 12-21-2020 at 12:34 AM.

  4. #4
    Forum Contributor
    Join Date
    12-08-2020
    Location
    South Korea
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    This code : Change all inlineShape's Alternative Text with Previous Paragraph

    The Data Format in Word like this.
    paragragh1
    [inlines]
    paragragh2
    [inlines]
    paragragh3
    [inlines]

    Please Login or Register  to view this content.
    Last edited by chronjy; 12-21-2020 at 12:28 AM.

  5. #5
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    OK. That looks reasonable but how would you execute that code at this distinct point of program execution time where InlineShape is found in this routine> 'Call GetPrevHeadingLevel?
    I will give it a quick run but previous attempts like this have cratered on the C.Select. Stand by and thanks for your time!


    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    Run time error 448 on line: Selection.Previous(Unit:=wdParagraph, Count:=1).Select (Named argument not found)

  7. #7
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    Also, I made Dim C as Variant. (It's not Object is it?)

  8. #8
    Forum Contributor
    Join Date
    12-08-2020
    Location
    South Korea
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    ==================
    Dim i As Integer
    Dim c As Word.InlineShape
    Dim doc As Word.Document
    ===================
    * the variable Names can be changable
    I think the key is moving inlineshapes and get previous paragraph
    And I am not sure about "GetPrevHeadingLevel"? do you need to get the Level of previous paragraph also???


    i hope this help.
    Last edited by chronjy; 12-21-2020 at 01:23 AM.

  9. #9
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    I'm still getting a 448 on the Selection.Previous(Unit:=wdParagraph, Count:=1).Select. I'm thinking since wrdDoc is pointing to an InlineShape (not a paragraph) the Select previous paragraph statement doesn't work. Do I need to translate my current position with InlineShapes to a bookmark or something else before attempting the Selection.Previous(Unit:=wdParagraph, Count:=1).Select? They don't seem to be compatible.

  10. #10
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    Or could it be something between running Excel VBA running on a Word doc? I also see posts about doing a bind but not sure about how to use it or if it's even necessary.

  11. #11
    Forum Contributor
    Join Date
    12-08-2020
    Location
    South Korea
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    matching inlineShapes' alternative text to right before outline text

    Please Login or Register  to view this content.
    Last edited by chronjy; 12-22-2020 at 12:15 AM.

  12. #12
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    You are a Wizard A True Star (Todd Rundgren)! That did the trick!

    The approach you used is straightforward yet something I would never have come up with. Using OutlineLevel is a new concept to me.

    Truly thanks chronjy !

  13. #13
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    Just curious but what is the DIM for c and lvTmp? It works but for reference I would like them declared.....plus I use Explicit.

    I found what it should be: c is Dim Word.Inlineshape
    Last edited by pmrsed; 12-21-2020 at 08:03 PM.

  14. #14
    Forum Contributor
    Join Date
    12-08-2020
    Location
    South Korea
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Excel VBA to Update Word InlineShapes using Previous Heading Text

    Dim doc As Document
    Dim Paragraph As Word.Paragraph
    Dim lvTmp As Integer, cnt As Integer, strTemp As String
    Dim c As Word.InlineShape

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] need to update querries to link to a new excel file which replaces previous one.
    By Nomadicbrain in forum Access Tables & Databases
    Replies: 5
    Last Post: 11-04-2020, 10:23 AM
  2. [SOLVED] Find certain word, copy and paste cell in previous row if previous row is blank
    By steven_e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2013, 12:53 PM
  3. Replies: 2
    Last Post: 05-28-2013, 12:41 AM
  4. userform combobox rowsources chosen by heading match to previous comboxbox selection
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2009, 02:38 PM
  5. Changing a Numeric Heading to Text in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 11-04-2007, 05:46 AM
  6. Heading rows repeat in word embedded excel table
    By Turnipboy in forum Excel General
    Replies: 0
    Last Post: 06-23-2005, 04:38 AM
  7. Pasted text from Excel to Word replaces previous paragraph
    By TT in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-20-2005, 03:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1