Results 1 to 6 of 6
  1. #1
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65

    Office Interop - Styling Selections in an opened Word Document

    So the reporting ability of Access is woefully limited, which means I'm going to need to write my reports to build out in Word. That's all well and good. I've been trying to apply Styles - because they have a role in Word's conversion to PDF. I can apply styles to an entire Paragraph, but not a Selection. It's weird, because the font changes apply but the selection itself is not set as being in that Style.



    Here's the code I'm using. It creates the text and applies the style. Before this there's a function that defines the style, opens a new word document, and then this runs
    Code:
        Dim varword As String
        Dim myRange As Word.range
        
        varword = "One New Customer"
        wordDoc.range.text = vbTab & "Customer:" & vbTab & varword & vbTab & "Incident Notifications:" & vbTab & "notifications@onenewcust.com" & vbNewLine _
            & vbTab & "Tier:" & vbTab & "Platinum" _
            & vbTab & "Customer Surveys:" & vbTab & "surveys@onenewcust.com" & vbNewLine _
            & vbTab & "Status:" & vbTab & "On-Boarding" _
            & vbTab & "Performance Summaries:" & vbTab & "perfsum@onenewcust.com" & vbNewLine
        wordDoc.Paragraphs(4).range.InlineShapes.AddHorizontalLineStandard
        
        Set myRange = wordDoc.range(11, 11 + Len(varword))
        myRange.Select
    edit: I'm tired and losing my mind...

    THIS works but applies the style to the entire row:
    myRange.Style = wordDoc.Styles("Heading 1")

    however this does not, but does apply the font changes to the selection
    wordApp.Selection. = wordDoc.Styles("Heading 1")

    basically, applying the style to Range sets the entire Paragraph to the style, but applying it to the Selection just does font changes without actually applying a style.

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    In that code, I do see you select the part of wordDoc.range that should contain the text "One New Customer". I'm not seeing any attempt to apply a style to that selection. At the end of your code, I'd expect something like this -

    MyRange.Style = ActiveDocument.Styles("MyStyle")


    You might want to try over at the Word forums, since it's Word that's not acting as you expect it to work.

    http://www.msofficeforums.com/word-vba/

  3. #3
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    sorry, the edit there is relevant, I realized I completely forgot to include that point.

    Right now I'm tring setting it up as a table a la archaic HTML design

    edit: I'm tired and losing my mind...

    THIS works but applies the style to the entire row:
    myRange.Style = wordDoc.Styles("Heading 1")

    however this does not, but does apply the font changes to the selection
    wordApp.Selection. = wordDoc.Styles("Heading 1")

    basically, applying the style to Range sets the entire Paragraph to the style, but applying it to the Selection just does font changes without actually applying a style.

  4. #4
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Okay, in MS Word VBA this may be a newbie question, but is the Style that you are attempting to apply to this selection a "Paragraph" Style, or a "Font" Style? I'm betting you need to either define and use a Font style, or include a paragraph break in your text, to get what you are asking it to do...

  5. #5
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    I'm applying the style "Header 1" - which is a paragraph style I believe but includes font changes? I'm trying to do it without line breaking the Paragraph though. Not sure if that can be done. Either way, I do have it working by setting it up as a table, mostly.

  6. #6
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    That's your issue. Styles come in types. Since Header 1 is a paragraph style, it only applies to a paragraph object - all or nothing. Word has attempted to comply with your two different requests in two different ways - applying the paragraph style and simulating the style with font changes.

    I'm not sure if you can have a Font style that derives directly from a paragraph style or not, but you really need to take those questions over to the Word forum, and mark this thread solved.

    Take care!

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

Similar Threads

  1. Embed word document into form
    By jgelpi16 in forum Forms
    Replies: 4
    Last Post: 06-26-2012, 11:31 AM
  2. Create new Word document.
    By Bill H in forum Programming
    Replies: 3
    Last Post: 06-12-2012, 06:40 AM
  3. Import Word document using VBA
    By degras in forum Import/Export Data
    Replies: 4
    Last Post: 04-12-2011, 02:40 AM
  4. Mail Merge document locked when opened from Access
    By retro in forum Import/Export Data
    Replies: 0
    Last Post: 08-14-2009, 03:12 AM
  5. Cannot load image in Microsoft Office Document Imaging
    By chrisjohns in forum Programming
    Replies: 1
    Last Post: 04-03-2009, 02:45 AM

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