Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
|
|||
|
|||
![]()
Hi Sarah,
I've been away for a few weeks, so didn't get a chance to reply earlier. I'm not familiar with the PasteExcelTable method - presumably its from a Word version later than 2000, which is what I use. Using Word 2000, you could do it with code like: rng.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, _ Placement:=wdInLine, DisplayAsIcon:=False rng.Select With Wdoc.Selection .Expand (wdParagraph) '.Fields(1).Select 'for the first field in the para '.Fields(.Fields.Count).Select 'for the last field in the para .Bookmarks.Add Name:=TableID, Range:=Selection End With Note the commented-out code for selecting the fields. You can use one of these if the para you're adding the table to might already have more than one field in it. Cheers -- macropod [MVP - Microsoft Word] "hornbecky83" wrote in message oups.com... | I am not sure how to do this, I was barely able to figure out how to | add a bookmark to the table. Can you please provide me an example or | point me to one? Thanks so much for all your help! | | Sarah | | | macropod wrote: | Hi Sarah, | | I suspect the problem is that you're putting the bookmark within the LINK | field that was created when you inserted the Excel Worksheet. What you need to | do in this case is to bookmark the corresponding LINK field, not the table. | That should survive any link updates. | | Cheers | | -- | macropod | [MVP - Microsoft Word] | | | "hornbecky83" wrote in message | ups.com... | | Hi- | | | | I decided to use the bookmark techinique. The advice everyone gave me | | was great, the bookmark method seemed the better approach for my | | project. However, now I am having a problem with the bookmarks. I was | | able to bookmark my tables in excel for when they are put into my word | | document. I need my tables linked, so I pasted the tables in word | | linked to the excel. When I save my document and then re-open it and | | agree to updating my links to my tables, the bookmark goes away. If I | | don't update then everything still works. How can I make it so the | | bookmark will be maintained when I update my table links? Is this | | possible? Below is a summed up version of my code. Thank you! | | | | Sarah | | | | | | Dim Wdoc As Word.document | | Dim Wapp As Word.Application | | Dim rng As Word.Range | | Dim xlMissionDesign As Excel.Workbook | | Dim x As Integer | | Dim y As Integer | | Dim BtnName As String | | Dim shp As Word.InlineShape | | Dim scode As String | | Dim TableID As String | | Dim ParagID As String | | | | Set Wapp = CreateObject("Word.Application") | | Wapp.Visible = True | | Wapp.Documents.Add | | Set Wdoc = Wapp.ActiveDocument | | | | Set rng = Wdoc.Paragraphs.Last.Range | | | | For i = 1 To x | | | | For i = 1 to y | | | | 'copies my table from excel | | rng.Style = "Normal" | | Worksheets("Report Tables").Activate | | Worksheets("Report Tables").Range("MissionOrbitParams").Select | | Workbooks.Application.CutCopyMode = False | | Workbooks.Application.Selection.Copy | | | | 'this paste my table into word, linked. It also creates the table | | bookmark. | | ParagID = "ParagBookMark" & i & j | | TableID = "TableBookMark" & i & j | | rng.InsertParagraphAfter | | Set rng = Wdoc.Paragraphs.Last.Range | | rng.PasteExcelTable linkedtoexcel:=True, wordformatting:=False, | | RTF:=False | | rng.Tables(1).Range.Select | | Wdoc.Bookmarks.Add Name:=TableID, | | Range:=Wdoc.Application.Selection.Range | | | | BtnName = "OrbitButton" & i & j | | | | 'This creates my button. | | Set shp = rng.document.InlineShapes.AddOLEControl _ | | (ClassType:="Forms.Commandbutton.1", | | Range:=Wdoc.Paragraphs.Last.Range) | | shp.OLEFormat.Object.Caption = "Add Orbit" | | shp.OLEFormat.Object.Name = BtnName | | | | 'This puts code behind my button, where it calls the bookmarks I | | created and works with them | | 'in the word document | | scode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & | | vbCrLf & _ | | "If Not ActiveDocument.Bookmarks.Exists( " & Chr(34) & ParagID & | | Chr(34) & ") Then" _ | | & vbCrLf & _ | | "MsgBox Prompt:=""Bookmark Paragraph not found"", Title:= | | ""Error""" & vbCrLf & _ | | "Exit Sub" & vbCrLf & _ | | "End If" & vbCrLf & _ | | "If Not ActiveDocument.Bookmarks.Exists(" & Chr(34) & TableID & Chr(34) | | & ") Then" _ | | & vbCrLf & _ | | "MsgBox Prompt:=""Bookmark Table not found"", Title:= ""Error""" & | | vbCrLf & _ | | "Exit Sub" & vbCrLf & _ | | "End If" & vbCrLf & _ | | vbCrLf & _ | | "ActiveDocument.Bookmarks(" & Chr(34) & TableID & Chr(34) & ").Select" | | & vbCrLf & _ | | "Selection.Copy" & vbCrLf & _ | | vbCrLf & _ | | "ActiveDocument.Bookmarks(" & Chr(34) & ParagID & Chr(34) & | | ").Select" & vbCrLf & _ | | "ActiveDocument.Application.Selection.MoveUp Unit:=wdLine, | | Count:=1" & vbCrLf & _ | | vbCrLf & _ | | "Selection.InsertParagraphAfter" & vbCrLf & _ | | "Selection.Paste" & vbCrLf & _ | | "Selection.InsertParagraphAfter" & vbCrLf & _ | | vbCrLf & _ | | "Selection.MoveRight Unit:=wdCharacter, Count:=1" & vbCrLf & _ | | vbCrLf & _ | | "End Sub" | | | | Application.ActivateMicrosoftApp xlMicrosoftWord | | | | 'this applys my code | | | | Wdoc.VBProject.VBComponents("ThisDocument").CodeMo dule.AddFromString | | scode | | | | Next j | | Next i | | | | | | macropod wrote: | | Hi Sarah, | | | | If you assign a bookmark to the table, you can always find the table again | via | | the bookmark - provided you're careful about putting another table within | the | | bookmark range and not moving/deleting the bookmark. | | | | Another way would be to put the table inside a text box. Being a shape | object, | | a textbox can be named (best done when created). Again, you'd have to be | | careful about putting another table into the same textbox. | | | | Cheers | | -- | | macropod | | [MVP - Microsoft Word] | | | | | | "hornbecky83" wrote in message | | ups.com... | | | Hi- | | | | | | I am working remotely in word vba through excel vba. Basically I have | | | programed in excel to create a new word document, add a button, and | | | then add code to the word document for when the button in excel is | | | clicked. The code I am adding to the word document needs to copy a | | | table and paste it (right above the button). I figured out how to copy | | | a table if you give it an index number, but with the other code I am | | | running the number of tables always changes. Therefore hardcoding an | | | index number is a bad idea. I will end up copying different tables | | | each time and not the one I want. Is it possible to add a name or | | | range to that table, so I can just copy the table name or range? | | | | | | If this is not possible, I wanted to know if its possible to code | | | adding an excel reference library in word. If I have the word document | | | button code remote access excel to get the named table range that way, | | | I need to figure out how to code an excel reference library into the | | | button code. I do not know how or if this is possible. Manually | | | setting it is not an option. I really hope someone can help me! Thank | | | you so much in advance. | | | | | | sarah | | | | | | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Naming word tables or coding reference library with vba | Charts and Charting in Excel | |||
Word Library reference | Excel Programming | |||
Reference Library - Missing Library in a lower version. | Excel Programming | |||
adding reference to the Word-Library | Excel Programming |