Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.word.vba.userforms
external usenet poster
 
Posts: 21
Default Link table from excel to word using word VBA

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 :-)

  #2   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.word.vba.userforms
external usenet poster
 
Posts: 6
Default Link table from excel to word using word VBA

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 :-)


  #3   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.word.vba.userforms
external usenet poster
 
Posts: 21
Default Link table from excel to word using word VBA

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

If you include the Type argument, then you have to leave out the word
LINK in the Text argument. If you set PreserveFormatting:=True, then you
should leave \* MergeFormat out of the Text argument.

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 :-)

  #4   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.word.vba.userforms
external usenet poster
 
Posts: 11
Default Link table from excel to word using word VBA

Thank you Cindy that helped alot! Thanks for sticking with me. I
wanted to ask you another question if you don't mind. Do you know how
to bookmark a link field. I want to add a bookmark to a table, but
everytime I update my table links, the bookmark goes away. It was
suggested to me to bookmark the link field, but I do not know how to do
this. Do you have any suggestions or know where to point me? Is there
another method you would suggest for maintaining the bookmark with a
table link updates? Thanks again for all you help.

Sarah

I had another question that related
Cindy M. wrote:
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

If you include the Type argument, then you have to leave out the word
LINK in the Text argument. If you set PreserveFormatting:=True, then you
should leave \* MergeFormat out of the Text argument.

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 :-)


  #5   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.word.vba.userforms
external usenet poster
 
Posts: 21
Default Link table from excel to word using word VBA

Hi Hornbecky83,

Thanks for sticking with me. I
wanted to ask you another question if you don't mind. Do you know how
to bookmark a link field. I want to add a bookmark to a table, but
everytime I update my table links, the bookmark goes away. It was
suggested to me to bookmark the link field, but I do not know how to do
this. Do you have any suggestions or know where to point me? Is there
another method you would suggest for maintaining the bookmark with a
table link updates?

I peripherally followed your discussion about that, but since I basically
agreed with what "macropod" told you, I didn't jump in there...

You should be able to see the LINK field if you press Alt+F9. You'll need
to select a paragraph above (and also maybe below) the field in order to
create a bookmark that updating the field won't delete.

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 :-)



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Word Table from a Excel Macro Silvia Excel Discussion (Misc queries) 0 September 7th 06 12:34 AM
Macro to Extract Text From Word Table Into Excel? V. Hatherley Excel Discussion (Misc queries) 1 August 27th 06 04:12 PM
Paste Table from Word in Excel - 2000 -vs- 2002 PeteW Excel Discussion (Misc queries) 3 April 27th 06 07:36 AM
Extract MS Excel Data embedded in MS Word qualityprocess Excel Discussion (Misc queries) 0 April 20th 06 05:52 PM
TRYING TO SET UP EXCEL SPREADSHEET ON MY COMPUTER MEGTOM New Users to Excel 5 October 27th 05 03:06 AM


All times are GMT +1. The time now is 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"