#1
|
|||
|
|||
set headings in a VBA inserted text to use for index
Hey People, hope you can help me.
I made a VBA in Excel, where i have all my data, to generate a document in Word. By clicking a button in Excel a template word document is opened and info from excel is added to the word document. First a line of text is added, and then a few pics. That process is repeated several times. I would like the line of text to be "heading 2" in word and the pics as "normal" so i only have to update my table of contents and get all the lines of text in there. I've come up wuth this, but it doesn't work, it makes the whole document "normal" Hope one of you has the answer! Set range2 = appwd.ActiveDocument.Content For i = 6 To Sheets.Count range2.Collapse Direction:=wdCollapseEnd range2.Style = "kop 2" Worksheets(i).Range("AU20").Copy Application.Wait (Now + TimeValue("0:00:01")) range2.PasteSpecial Placement:=wdInLine, DataType:=wdPasteText Application.CutCopyMode = False 'copy paste acties For j = 1 To 6 range2.Collapse Direction:=wdCollapseEnd range2.Style = "standaard" Worksheets(i).Range(bereik(j)).Copy Application.Wait (Now + TimeValue("0:00:01")) range2.PasteSpecial Placement:=wdInLine, DataType:=wdPasteMetafilePicture Application.CutCopyMode = False Next j Next i |
#2
|
||||
|
||||
The problem is that you are pasting the items after the range and then formatting the range. Without your workbook it is impossible to check, but the following should be closer:
Code:
For i = 6 To Sheets.Count range2.Collapse direction:=0 range2.Style = "kop 2" Worksheets(i).Range("AU20").Copy Application.Wait (Now + TimeValue("0:00:01")) range2.PasteSpecial Placement:=0, DataType:=2 appwd.ActiveDocument.Range.InsertParagraphAfter range2.End = appwd.ActiveDocument.Range.End range2.Paragraphs(1).Style = "kop 2" Application.CutCopyMode = False 'copy paste acties For j = 1 To 6 range2.Collapse direction:=0 Worksheets(i).Range(bereik(j)).Copy Application.Wait (Now + TimeValue("0:00:01")) range2.PasteSpecial Placement:=0, DataType:=3 appwd.ActiveDocument.Range.InsertParagraphAfter range2.End = appwd.ActiveDocument.Range.End range2.Paragraphs(1).Style = "standaard" Application.CutCopyMode = False Next j Next i
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Yesss
sorry @gmayor , Took a while to find time to work on it again, but it works perfect. thx a million
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Underline Inserted Text | jmltinc | Word VBA | 9 | 02-08-2017 08:10 AM |
align text when textbox inserted later | ketanco | Word | 1 | 06-19-2016 01:21 PM |
Is there a way of having text automatically inserted based on the selection of other text? | MiniMum97 | Word | 2 | 04-12-2016 06:09 AM |
Text disappears (but headings and text boxes ok) when printing 1 page of a document | msfordummies | Word | 1 | 02-21-2013 10:28 PM |
Automatic text on inserted slides | tom_kladno | PowerPoint | 0 | 05-12-2011 04:30 AM |