#1
|
|||
|
|||
don't know how to use ".wholestory" method
Hello, I am in Excel VBA UserForm. I have a long string text containing lots of chr(10) and chr (13) and I need to sent this string to a Word file. However after I sent I found lots of blank lines in the Word document and I had to manually "select all" and do "reduce the space between rows". Later I added a code to select the whole text in Word, but I don't know how to use "WholeStory" method to delete all these blank rows in the selected text. My code is as below (in Excel VBA):
Private Sub ScopeSendToWord Dim objWordFile As Word.Application Set objWordFile = New Word.Application objWordFile.Documents.Add objWordFile.ActiveDocument.Range.Text = txtScope (txtScope is a string text which I want to export to a Word file, the code works and I can see the content in Word file) objWordFile.ActiveDocument.Range.Select (selecting text in Word file) Selection.WholeStory (this is the code I added but I can't get through and I need help here) objWordFile.Visible=True End Sub Thank you so much. Jason |
#2
|
||||
|
||||
You don't need to do anything regarding StoryRanges; what you need to do is:
• modify the Style of the paragraphs concerned, reducing the before/after spacing; and/or • use Find/Replace process to delete empty paragraphs.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi, Paul;
Thank you very much. I will try what you suggested. Since this is an Excel/Word combined situation, I was not sure which forum I should go. Sorry about it. Thank you again. Jason |
#4
|
|||
|
|||
Hi, Paul;
I made the following code and it works: With objWordFile.ActiveDocument Dim myParagraphs As Paragraphs Dim myparagraph As Paragraph Set myParagraphs = .Paragraphs For Each myparagraph In myParagraphs myparagraph.Range.ParagraphFormat.SpaceAfter = 0 Next End With Thank you again for your guidance. Jason |
#5
|
||||
|
||||
Hi Jason,
That really is the wrong way to go about the process. As previously advised, you should modify the appropriate Style. Unnecessarily overriding paragraph Styles with different formats is ill-advised as it makes documents harder to maintain and can cause instability. Since most documents use the 'Normal' Style as their default, the following demos how to reformat the document to use 11pt Arial with 0 before/after space and single line spacing as the paragraph format, without ever touching the document content: Code:
Private Sub ScopeSendToWord() Dim WdApp As Word.Application Dim WdDoc As Word.Document Set WdApp = New Word.Application Set WdDoc = WdApp.Documents.Add With WdDoc .Range.Text = txtScope With .Styles("Normal") With .ParagraphFormat .SpaceBefore = 0 .SpaceAfter = 0 .LineSpacingRule = wdLineSpaceSingle End With With .Font .Name = "Arial" .Size = 11 End With End With End With WdApp.Visible = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Error: "Changes made were lost...reconnect with server", when switching "from" field | randhurrle | Outlook | 2 | 02-25-2015 06:51 PM |
When composing an e-mail how do I add "Page Layout" and "View" tabs to the ribbon | CensorTilSin | Outlook | 1 | 12-11-2013 12:05 PM |
help with compatibility of "WdSaveFormat" property of SaveAs method | ajetrumpet | Word | 0 | 07-15-2013 07:29 AM |
Method to active "Select Drawing Objects" | rgustin | Word VBA | 1 | 08-18-2012 11:58 AM |
How to choose a "List" for certain "Heading" from "Modify" tool? | Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |