Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert bookmark using Style

    Hello,

    I need to insert bookmark text from a file, but the text needs to be formatted to the current selection style

    The text goes in using:

    Selection.InsertFile FileName:=aFileName, Range:=aText

    where aText is the bookmark name. But the text inserts with the formatting as per the bookmark (source) not the document selection (destination). How can I set the inserted text to the current paragraph style? Thanks.
    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>

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert bookmark using Style

    Hi Kevin:
    I am not a VBA expert by any means, but as I was perusing this forum, I noticed your question. I do know that

    RichText: = True

    will insert formatted text. Therefore, I would guess that

    RichText: = False

    would insert unformatted text (i.e. it would take the formatting of the current paragraph.

    Hope this works.

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

    Re: Insert bookmark using Style

    Phil,

    Thanks for the post. That was a pretty educated guess, but the insertfilename method does not support the richtext property like the autotext insert does. Not that I can see.
    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. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 28 Times in 27 Posts

    Re: Insert bookmark using Style

    Hi Kevin,
    (Are the pictures to distinguish you from 'Big Kev'?)

    I found some code I inherited that's pretty much the same as what you've got, and it works fine (difference being the optional ConfirmConversions, Link and Attachments arguments were included and set to False - can't see what purpose that serves).

    So it seems like the proverbial 'something else' is going on.
    Just to grasp at a couple of straws:
    Does the bookmarked source text contain paragraphs - if so the paragraph marks might bring in their own formatting.
    Does the target text have any direct formatting applied on top of the applicable style?
    Could the formatting be adjusted in the bookmarked source text to compensate?

    Gary

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

    Re: Insert bookmark using Style

    Hey, where is BigKev anyway? All the Kevins are not back yet.

    The pictures are just for laughs.

    Yes, the bookmark source text contains paragraphs

    No, the target text has only the style for paragraph formatting.

    No, the formatting in the source cannot be adjusted because sometimes the text is inserted into double-spaced paragraphs, single-spaced, double-indented, etc.
    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>

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

    Re: Insert bookmark using Style

    Hard to figure why the problem is happening.
    As a workaround, how about something like:

    Dim rngInsert As Range
    rngInsert = Selection.InsertFile(FileName:=aFileName, Range:=aText)
    rngInsert.ParagraphFormat.Reset

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

    Re: Insert bookmark using Style

    Gary,

    This code looked like a possible answer, but it no workie.
    Compiler error: Expected Function or variable.

    Did I miss something? Thanks.
    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>

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

    Re: Insert bookmark using Style

    If it's hanging up on the "aFileName" or "aText": those were the variable names included in your original posting. Is it hanging on something else?

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

    Re: Insert bookmark using Style

    It bombs on the rngInsert = Selection.Insertfile line. VBE highlights Insertfile.

    Could this be unsupported in Word 97?
    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>

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

    Re: Insert bookmark using Style

    True confession: this was scratch code (I compiled it, but did not run it). How embarrassing[img]/w3timages/icons/blush.gif[/img].
    When I get in to work a bit later, I'll hack around with this a little more thoroughly.[img]/w3timages/icons/crazy.gif[/img]

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

    Re: Insert bookmark using Style

    Aha! An imposter! You're really a politician, not a programmer, right? No. You're a lawyer! No wait. You're a waitress who masquerades as a mild-mannered Lounger secretly trying to gain access to Pentagon files and this is as far as you got! Ha! We caught you.
    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>

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

    Re: Insert bookmark using Style

    You're onto me with that last bit - how did you find out?[img]/w3timages/icons/alien.gif[/img]

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

    Re: Insert bookmark using Style

    It was a dead giveaway in the white spaces between the lines of your posts.

    But, even if you are an alien, if you could figure this one out, I'd be abliged. I'm working an angle too. Let you know if I get it.
    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>

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

    Re: Insert bookmark using Style

    Gary,

    I got it!

    Get this. When the bookmark gets inserted from the source, it's created as a new bookmark in the destination. So...
    I get the current paragraph number, save the style there, then apply the style to the new bookmark!

    <pre>iPara = GetParagraphNumber

    lStyle = ActiveDocument.Paragraphs(iPara).Style

    Selection.InsertFile FileName:=vMacLoc + aFileName, Range:=aText
    ActiveDocument.Bookmarks(aText).Select
    Selection.Style = lStyle
    </pre>


    Success!
    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>

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

    Re: Insert bookmark using Style

    Alright!

    I assume GetParagraphNumber is a custom function?
    Even simpler, couldn't you use:

    lStyle = Selection.Paragraphs(1).Style '?
    (no, I didn't try running this one first either!)[img]/w3timages/icons/tonguea.gif[/img]

Page 1 of 2 12 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
  •