Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hyperlink problem

Status
Not open for further replies.

johnmtb

Programmer
Jul 12, 2008
37
US
Dear All,

I have successfully written a programme that links a cell in one .xls file to a cell in another .xls file. I now want to accomplish the same thing using .doc files.

I have created two files, one the source and the other the destination. Both files contain tables with identical numbers of rows and columns. The source file is populated already and I want to link cells in the destination file to cells in the source file.

However, what happens is that the table in the destination file disappears, and the 6 cells from the source file are simply written over each other in the destination file; in the top left hand corner. Furthermore, unlike what occurs in the .xls files, when o Ctrl/click the link, it does not go to the source cell, but to the top left hand corner of the source file.

When I use the “Record New Macro”, it works the way I want it to, and when I study the code produced it is practically identical to mine. So what am I doing wrong? And why does the table in the destination file disappear?

I am using VB.Net 2008.

Code:
LineItems = 6

i = 1
j = 3
k = 3

WordTableCell = WordFile02.Tables(1).Rows(3).Cells(2)
WordTableCell.Select()
WordObj.Selection.MoveRight()
InvName = WordFile01.Tables(i).Rows(j).Cells(k).Range.Text
InvName = Left(InvName, Len(InvName) – 2)

For x = 1 To LineItems
	WordFile01.Tables(i).Rows(j).Cells(k).Range.Select()
	WordFile02.Activate()
	WordFile02.Hyperlinks.Add(Anchor:=WordFile02.Range,Address:=_ "C:\z\Test01.doc",SubAddress:="WordFile01.Tables(1).Rows(j).Cells(k)",_ TextToDisplay:=CStr(InvName))
	j = j + 1
	InvName = WordFile01.Tables(i).Rows(j).Cells(k).Range.Text
	InvName = Left(InvName, Len(InvName) - 2)
Next

Regards,

John
 
When I use the "Record New Macro", it works the way I want it to, and when I study the code produced it is practically identical to mine.
Your answer then really is likely in the differences. When working with things directly from Word/Excel you are technically working in Word/Excel. Someone may have done what you have before or may have more time to try it, but to hold you over till then I suggest taking a closer look at what those differences. You might think of it as the fact basically all you are doing is sending commands to Word and Word is doing the work through VBA. I do most of my work in Excel and Access or I might have a better suggestion for you.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top