ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Re-Post: Embedded Word File (https://www.excelbanter.com/excel-programming/414285-re-post-embedded-word-file.html)

Troubled User

Re-Post: Embedded Word File
 
I have an Excel File that has an embedded Word File in it. The embedded Word
file contains a table with say 5 rows and 3 columns.

Additionally, in this file I have a text box (Textbox1). I am trying to
copy the contents of Textbox1 to Row 2, column 2 of the table within the
embedded Word file.

I have done a fair amount of copying between Textboxes/cells and Textbox to
Textbox, but I don't know how to reference this table and location in the
embedded Word file.

Any help is very appreciated.




joel

Re-Post: Embedded Word File
 
I saw youor earlier posting but didn't have time to respond. This code
should work. Change "ABC" to read the data from your text box.

Sub gettable()

For Each obj In ActiveSheet.OLEObjects
If InStr(obj.progID, "Word.Document") 0 Then
'open word document
obj.Activate

Set WordDoc = obj.Object.Application.ActiveDocument
MyRow = 2
MyCol = 2
For Each tbl In WordDoc.tables
tbl.cell(MyRow, MyCol).Range.Text = "ABC"
Next tbl

End If

Next obj

End Sub


"Troubled User" wrote:

I have an Excel File that has an embedded Word File in it. The embedded Word
file contains a table with say 5 rows and 3 columns.

Additionally, in this file I have a text box (Textbox1). I am trying to
copy the contents of Textbox1 to Row 2, column 2 of the table within the
embedded Word file.

I have done a fair amount of copying between Textboxes/cells and Textbox to
Textbox, but I don't know how to reference this table and location in the
embedded Word file.

Any help is very appreciated.




Troubled User

Re-Post: Embedded Word File
 
Thank you VERY much. I will try a little later tonight and let you know if I
have any problems.

"Joel" wrote:

I saw youor earlier posting but didn't have time to respond. This code
should work. Change "ABC" to read the data from your text box.

Sub gettable()

For Each obj In ActiveSheet.OLEObjects
If InStr(obj.progID, "Word.Document") 0 Then
'open word document
obj.Activate

Set WordDoc = obj.Object.Application.ActiveDocument
MyRow = 2
MyCol = 2
For Each tbl In WordDoc.tables
tbl.cell(MyRow, MyCol).Range.Text = "ABC"
Next tbl

End If

Next obj

End Sub


"Troubled User" wrote:

I have an Excel File that has an embedded Word File in it. The embedded Word
file contains a table with say 5 rows and 3 columns.

Additionally, in this file I have a text box (Textbox1). I am trying to
copy the contents of Textbox1 to Row 2, column 2 of the table within the
embedded Word file.

I have done a fair amount of copying between Textboxes/cells and Textbox to
Textbox, but I don't know how to reference this table and location in the
embedded Word file.

Any help is very appreciated.




Troubled User

Re-Post: Embedded Word File
 
Joel,

Your code worked great with a couple of minor modifications to adjust for
length constraints (I looped multiple times). So thank you very much.

The final problem I am having is determining if the text I moved is
bold/underlined/etc. I have been trying to adapt code that I run against
Excel textboxes such as:

For Counter1 = 1 To Source1.Characters.Count
If Source1.Characters(Counter1, 1).Font.Bold Then
Target1.Characters(Counter1, 1).Font.Bold = True
End If


I have tried numerous variations to get at the individual characters within
the Word tables, such as:

MsgBox (tbl.cell(2, 1).Range.Characters(1, 1))
MsgBox (tbl.cell(2, 1).Range.Text.Characters(1, 1))
MsgBox (tbl.cell(2, 1).Characters(1, 1))

And on and on.

I don't know how to get at the characters within the table object. Any help
you could provide would be greatly appreciated.

Thanks again!




"Troubled User" wrote:

Thank you VERY much. I will try a little later tonight and let you know if I
have any problems.

"Joel" wrote:

I saw youor earlier posting but didn't have time to respond. This code
should work. Change "ABC" to read the data from your text box.

Sub gettable()

For Each obj In ActiveSheet.OLEObjects
If InStr(obj.progID, "Word.Document") 0 Then
'open word document
obj.Activate

Set WordDoc = obj.Object.Application.ActiveDocument
MyRow = 2
MyCol = 2
For Each tbl In WordDoc.tables
tbl.cell(MyRow, MyCol).Range.Text = "ABC"
Next tbl

End If

Next obj

End Sub


"Troubled User" wrote:

I have an Excel File that has an embedded Word File in it. The embedded Word
file contains a table with say 5 rows and 3 columns.

Additionally, in this file I have a text box (Textbox1). I am trying to
copy the contents of Textbox1 to Row 2, column 2 of the table within the
embedded Word file.

I have done a fair amount of copying between Textboxes/cells and Textbox to
Textbox, but I don't know how to reference this table and location in the
embedded Word file.

Any help is very appreciated.





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com