PDA

View Full Version : Wrong number of arguments or invalid property assignments in Excel ->word



neg
09-14-2018, 08:02 AM
Hi all, please can someone give me a pointer, I'm self taught and usually scour forums to help me find answers to get my code to work but in this case I'm struggling. Everything I read says the code below should work but.... I'm using Excel to open word and generate a document from a series of strings stored in the excel file. One of my strings needs to have a hyperlink added. So I set the display text as disp from a value from excel.
I then generate the hyperlink string by concatenating 2 fields as hyperadd (i'ts quite long).
I then search for a bookmark "law" and select the 8 character word straight after it.
Then I try to add the hyperlink at the selected txt and get "Wrong number of arguments or invalid property assignments".

Any ideas? (bound to be something simple!)

I suspect the issue is with the .range (and it not recognising my selection from the previous row but.....)

Thanks


If fieldtopass = "X9_0CX" Then Let disp = valuetopass
If fieldtopass = "X9_0DX" Then Let hyperadd = valuetopass
If fieldtopass = "X9_0EX" Then
Let hyperadd = hyperadd & valuetopass


With wrdDoc
.Bookmarks("law").Select
.Application.Selection.MoveRight Unit:=wdCharacter, Count:=8, Extend:=wdExtend
.Application.Selection.Hyperlinks.Add Anchor:=Selection.Range, Address:=hyperadd, TextToDisplay:=disp


End With
End If