Hi Cindy-
I tried doing what you said and that didn't seem to work. It wouldn't
accept the type:= Wapp.wdFieldEmpty so I replaced it with type:=
wdLinkTypeText. I tried several other versions and it still wouldn't
work. I was getting the same error. The other things I tried we
remove type argument, remove preserveformatting argument, remove both
type and preserveformatting argument, and remove range argument. The
last piece of code I tried was:
rng.Fields.Add Range:=Selection.Range, Type:=wdLinkTypeText, _
Text:="LINK Excel.Sheet.8 'C:\\Documents and
Settings\\shornbec\\Desktop\\sarah\\excel
templates\\Mission.FY07Q1_Sarah.xls' 'MissionTimelineDeltaVBudgetTable'
\a \f 4 \h \* MERGEFORMAT", PreserveFormatting:=True
I am really stuck with this. I pasted the rest of my incase you needed
it. Thank you for your help!
********************
Private Sub create_report()
Dim filename As String
Dim Wapp As Word.Application
Dim Wdoc As Word.Document
Dim dobj As New DataObject
Set Wapp = CreateObject("Word.Application")
Wapp.Visible = True
Wapp.Documents.Add
Set Wdoc = Wapp.ActiveDocument
Set rng = Wdoc.Paragraphs.Last.Range
rng.ListFormat.ApplyListTemplate Wdoc.Application.ListGalleries( _
wdOutlineNumberGallery).ListTemplates(5),
ContinuePreviousList:=False, _
ApplyTo:=wdListApplyToWholeList,
DefaultListBehavior:=wdWord9ListBehavior
rng.Style = "Title"
rng.InsertAfter "Contents"
rng.InsertParagraphAfter
Set rng = Wdoc.Paragraphs.Last.Range
rng.Style = "Normal"
Set rng = Wdoc.Paragraphs.Last.Range
With Wdoc.Application.ActiveDocument
.TablesOfContents.Add Range:=rng, RightAlignPageNumbers:=True,
_
UseHeadingStyles:=True, UpperHeadingLevel:=2, _
LowerHeadingLevel:=4, IncludePageNumbers:=True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
rng.InsertParagraphAfter
Set rng = Wdoc.Paragraphs.Last.Range
rng.InsertBreak Type:=wdSectionBreakNextPage
Dim rng As Word.Range
Dim xlMissionDesign As Excel.Workbook
Dim x As Integer
ThisWorkbook.Activate
Worksheets("more options").Activate
x = Worksheets("more options").Range("A1")
y = Worksheets("more options").Range("A2")
Call UseFileDialogOpen
Set rng = Wdoc.Paragraphs.Last.Range
rng.Style = "Heading 1"
rng.InsertAfter "Mission Design"
rng.InsertParagraphAfter
Workbooks("Mission.FY07Q1_Sarah.xls").Activate
For i = 1 To x
Set rng = Wdoc.Paragraphs.Last.Range
rng.Style = "Heading 3"
rng.Font.Underline = wdUnderlineSingle
rng.InsertAfter "Option" & " " & i
rng.InsertParagraphAfter
For j = 1 To y
Set rng = Wdoc.Paragraphs.Last.Range
rng.Style = "Heading 4"
rng.Font.Bold = False
rng.Font.Name = "Arial"
rng.Font.Size = 12
rng.InsertAfter "Flight Element" & " " & j
rng.InsertParagraphAfter
Set rng = Wdoc.Paragraphs.Last.Range
rng.Style = "List Bullet"
rng.InsertAfter "max DLA"
rng.ListFormat.ListIndent
rng.InsertParagraphAfter
Set rng = Wdoc.Paragraphs.Last.Range
rng.Style = "Normal"
Worksheets("Report Tables Delta V").Activate
Worksheets("Report Tables Delta
V").Range("MissionTimelineDeltaVBudgetTable").Sele ct
Workbooks.Application.CutCopyMode = False
Workbooks.Application.Selection.Copy
rng.InsertParagraphAfter
Set rng = Wdoc.Paragraphs.Last.Range
'rng.PasteExcelTable linkedtoexcel:=True,
wordformatting:=False, RTF:=False
' rng.Tables(1).Rows.Alignment = wdAlignRowCenter
'rng.Tables(1).AllowAutoFit = True
'rng.Tables(1).AutoFitBehavior wdAutoFitContent
rng.Fields.Add Range:=Selection.Range, Type:=wdLinkTypeText, _
Text:="LINK Excel.Sheet.8 'C:\\Documents and
Settings\\sbec\\Desktop\\sarah\\excel templates\\Mission_Sarah.xls'
'MissionTable' \a \f 4 \h \* MERGEFORMAT", PreserveFormatting:=True
Next j
Next i
end sub
Cindy M. wrote:
I tried writing code to add \*MERGEFORMAT with the previous VBA syntex
you wrote me, but it would not work. I kept getting a run-time error
'450': wrong number of arguments or invalid property assignment. I get
this error even when I change rng to Wdoc.Application.Selection, where
Wdoc = Wapp.ActiveDocument. Or when I add preserveformat = true. This
is the code I wrote:
rng.Fields.Add Range:=Selection.Range, Type:=xlWorksheet, _
Text:="LINK Excel.Sheet.8 C:\\Documents and
Settings\\shornbec\\Desktop\\sarah\\excel
templates\\Mission.FY07Q1_Sarah.xls MissionTimelineDeltaVBudgetTable \a
\f 4 \h \*MERGEFORMAT"
The Type argument is wrong; you don't need it since the LINK field name
is specified in the text. Remove it completely or use wdApp.wdFieldEmpty
(where wdApp is whatever variable name you're using for the
Word.Application). And put a space between \* and Mergeformat. You'll
probably also need to put the path in 'single quotes' since it contains
spaces.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)