Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2017, 07:48 AM
paul73 paul73 is offline set headings in a VBA inserted text to use for index Windows XP set headings in a VBA inserted text to use for index Office 2010 64bit
Novice
set headings in a VBA inserted text to use for index
 
Join Date: Jun 2017
Posts: 2
paul73 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 06-20-2017, 09:08 PM
gmayor's Avatar
gmayor gmayor is offline set headings in a VBA inserted text to use for index Windows 10 set headings in a VBA inserted text to use for index Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 08-07-2017, 05:31 AM
paul73 paul73 is offline set headings in a VBA inserted text to use for index Windows XP set headings in a VBA inserted text to use for index Office 2010 64bit
Novice
set headings in a VBA inserted text to use for index
 
Join Date: Jun 2017
Posts: 2
paul73 is on a distinguished road
Default Yesss

sorry @gmayor , Took a while to find time to work on it again, but it works perfect. thx a million
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
set headings in a VBA inserted text to use for index 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
set headings in a VBA inserted text to use for index 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft