bryVA
03-16-2010, 12:15 PM
Hello all,
I have a word document on a website and I want my excel program to open that document and then use the bookmarks that is on the document to insert information I input on the excel userform. I have the following code however this doesn't work.
Private Sub CommandButton2_Click()
Dim rep As String
Dim strFPath As String
Dim CSFile As String
Dim JulDate As String
Dim oWord As Object
Dim oDoc As Document
rep = UserForm13.ComboBox2.Value
rep = WorksheetFunction.Substitute(rep, " ", "%20")
strFPath = "http://vbaw.vba.com/bl/20/ofaa/access/vbrs/letters/" & ComboBox1.Value & "/" & rep & ".doc"
On Error Resume Next
Set oWord = GetObject(Class:="Word.Application")
If Err.Number > 0 Then
Err.Clear
Set oWord = CreateObject(Class:="Word.Application")
Else
End If
With oWord
.Application.Visible = True
Set oDoc = .Documents.Add(Template:=strFPath & rep & ".doc")
End With
End With
With oDoc
.Unprotect
.Bookmarks("BM_102").Range.Text = UserForm13.TextBox2.Value
.Bookmarks("BM_5").Range.Text = UserForm13.TextBox3.Value
.Bookmarks("BM_2").Range.Text = CSFile & Files
.Bookmarks("BM_6").Range.Text = UserForm13.TextBox4.Value
.Bookmarks("BM_7").Range.Text = UserForm13.TextBox5.Value
.Bookmarks("BM_600").Range.Text = UserForm13.ComboBox3.Value & " " & UserForm13.TextBox2
.Bookmarks("BM_601").Range.Text = UserForm13.TextBox6.Value
.Bookmarks("BM_602").Range.Text = UserForm13.TextBox7.Value & JulDate
End With
This works fine if the document is saved on a my computer or my regular server however when I post the document to my website server it can't find the file. Is there something I am doing wrong here?
If I can open the file using the following code but then I can't get excel to insert the information into the bookmarks.
ActiveWorkbook.FollowHyperlink Address:=strFPath, NewWindow:=True
How can I get the document to open and have the bookmarks filled in with the data from excel?
Thanks all,
-B
I have a word document on a website and I want my excel program to open that document and then use the bookmarks that is on the document to insert information I input on the excel userform. I have the following code however this doesn't work.
Private Sub CommandButton2_Click()
Dim rep As String
Dim strFPath As String
Dim CSFile As String
Dim JulDate As String
Dim oWord As Object
Dim oDoc As Document
rep = UserForm13.ComboBox2.Value
rep = WorksheetFunction.Substitute(rep, " ", "%20")
strFPath = "http://vbaw.vba.com/bl/20/ofaa/access/vbrs/letters/" & ComboBox1.Value & "/" & rep & ".doc"
On Error Resume Next
Set oWord = GetObject(Class:="Word.Application")
If Err.Number > 0 Then
Err.Clear
Set oWord = CreateObject(Class:="Word.Application")
Else
End If
With oWord
.Application.Visible = True
Set oDoc = .Documents.Add(Template:=strFPath & rep & ".doc")
End With
End With
With oDoc
.Unprotect
.Bookmarks("BM_102").Range.Text = UserForm13.TextBox2.Value
.Bookmarks("BM_5").Range.Text = UserForm13.TextBox3.Value
.Bookmarks("BM_2").Range.Text = CSFile & Files
.Bookmarks("BM_6").Range.Text = UserForm13.TextBox4.Value
.Bookmarks("BM_7").Range.Text = UserForm13.TextBox5.Value
.Bookmarks("BM_600").Range.Text = UserForm13.ComboBox3.Value & " " & UserForm13.TextBox2
.Bookmarks("BM_601").Range.Text = UserForm13.TextBox6.Value
.Bookmarks("BM_602").Range.Text = UserForm13.TextBox7.Value & JulDate
End With
This works fine if the document is saved on a my computer or my regular server however when I post the document to my website server it can't find the file. Is there something I am doing wrong here?
If I can open the file using the following code but then I can't get excel to insert the information into the bookmarks.
ActiveWorkbook.FollowHyperlink Address:=strFPath, NewWindow:=True
How can I get the document to open and have the bookmarks filled in with the data from excel?
Thanks all,
-B