C
CJ
My first ever attempt at VBA... and I've a problem.
I found that a Word document launched from a remote website will set its
ActiveDocument.FullName property to the full URI, including a posted form's
parameters.
I wrote the code below to do something useful with that information.
Setting string URI directly within the code works as expected, typing
the text 'Jimmy Cricket' into the document.
Setting string URI to ActiveDocument.FullName gives the error "Invalid
Procedure call or argument."
I'm sure I'm missing something obvious. How can I make this work?
Thanks in anticipation
CJ
Sub AutoOpen()
Dim URI As String
'URI = ActiveDocument.FullName
URI = "test.doc?action=doc&name=Jimmy+Cricket&nhs=4576845764"
Selection.TypeText URIExtract("name", URI)
End Sub
Function URIExtract(tag, URI) As String
Dim ParamStart As Integer
Dim ParamEnd As Integer
Dim Temp As String
' Find start of param (roughly)
ParamStart = InStr(1, URI, "&" + tag)
' ... then find the next '=', then jump it
ParamStart = InStr(ParamStart, URI, "=") + 1
' Find the '&' (signifies the end of the string)
ParamEnd = InStr(ParamStart, URI, "&")
If ParamEnd = 0 Then
' If position is '0' then final tag not found, meaning we're at the last expression
ParamEnd = Len(URI) + 1
End If
Temp = Mid(URI, ParamStart, ParamEnd - ParamStart)
' Remove URLEncoded spaces (+)
URIExtract = Replace(Temp, "+", " ")
End Function
I found that a Word document launched from a remote website will set its
ActiveDocument.FullName property to the full URI, including a posted form's
parameters.
I wrote the code below to do something useful with that information.
Setting string URI directly within the code works as expected, typing
the text 'Jimmy Cricket' into the document.
Setting string URI to ActiveDocument.FullName gives the error "Invalid
Procedure call or argument."
I'm sure I'm missing something obvious. How can I make this work?
Thanks in anticipation
CJ
Sub AutoOpen()
Dim URI As String
'URI = ActiveDocument.FullName
URI = "test.doc?action=doc&name=Jimmy+Cricket&nhs=4576845764"
Selection.TypeText URIExtract("name", URI)
End Sub
Function URIExtract(tag, URI) As String
Dim ParamStart As Integer
Dim ParamEnd As Integer
Dim Temp As String
' Find start of param (roughly)
ParamStart = InStr(1, URI, "&" + tag)
' ... then find the next '=', then jump it
ParamStart = InStr(ParamStart, URI, "=") + 1
' Find the '&' (signifies the end of the string)
ParamEnd = InStr(ParamStart, URI, "&")
If ParamEnd = 0 Then
' If position is '0' then final tag not found, meaning we're at the last expression
ParamEnd = Len(URI) + 1
End If
Temp = Mid(URI, ParamStart, ParamEnd - ParamStart)
' Remove URLEncoded spaces (+)
URIExtract = Replace(Temp, "+", " ")
End Function