Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
hornbecky83 hornbecky83 is offline
external usenet poster
 
Posts: 5
Default Naming word tables or coding reference library with vba

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

  #2   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
deano deano is offline
external usenet poster
 
Posts: 1
Default Naming word tables or coding reference library with vba

Sarah take a look at my post from a similar question here at
http://groups.google.com/group/micro...&q=deano&hl=en

Any chance
you can just use print statement to write one record at a time as
below:

Sub records_txtfile()
Dim ff As Integer
ff = FreeFile()
Open "C:\textfile.txt" For Output As ff
For r = Firstrecord To Lastrecord
' generate your record here
For c = FirstCol To lastcol
Print #ff, Cells(r, c);
Next c
Print #ff, 'blank line
Next r
Close ff
End Sub

take care,
deano

hornbecky83 wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Naming word tables or coding reference library with vba

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
|


  #4   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
hornbecky83 hornbecky83 is offline
external usenet poster
 
Posts: 5
Default Naming word tables or coding reference library with vba

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
|


  #5   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Naming word tables or coding reference library with vba

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




  #6   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
hornbecky83 hornbecky83 is offline
external usenet poster
 
Posts: 5
Default Naming word tables or coding reference library with vba

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


  #7   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.word.tables,microsoft.public.word.vba.general
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Naming word tables or coding reference library with vba

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


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 22 May 20th 23 08:51 PM
Why dont MS just f**king re-write Word from scratch? Its dogsh*t Word Hater Microsoft Word Help 33 May 5th 23 02:52 PM
How to put graphics on envelopes? Steve Koenig Microsoft Word Help 21 April 29th 23 02:47 AM
I am having difficulty with deleting headers and footers LHD New Users 5 July 24th 06 01:44 AM
Change paper size; Word changes to invalid margins OhioTech New Users 10 July 6th 06 02:00 PM


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

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"