Hello all, excuse my ignorance MSOffice isnt my usual thing but in the following code I have a command button that is to save a word document as a .doc file then delete the command button then save the document as a .htm file. The reason been I dont want the button showing on the .htm file. I am getting Invalid Call or Procedure when it gets to line commandbutton1.delete Any thoughts?
Private Sub CommandButton1_Click()
On Error GoTo error_handler
Dim sname As String
Dim fname As String
Dim response As Integer
Dim length As Long
Dim wname As String
wname = "eligible.doc"
fname = "eligible.htm"
length = FileLen("\\PIRNWFS1\VOL1\GRPDATA\HELPDESK\Operations\foobar\" & fname)
ChangeFileOpenDirectory "\\PIRNWFS1\VOL1\GRPDATA\HELPDESK\Operations\Foobar\"
ActiveDocument.SaveAs FileName:=wname, AddToRecentFiles:=True
Commandbutton1.Delete
ActiveDocument.SaveAs FileName:=fname, FileFormat:=wdFormatHTML, AddToRecentFiles:=True
ActiveWindow.View.Type = wdWebView
response = MsgBox("File saved as '" & fname & "', do you want to close document?", vbYesNo, "GODS"
If response = vbYes Then
ActiveDocument.Close
End If
Exit Sub
error_handler:
Select Case Err.Number
Case 53
length = -1
Resume Next
Case Else
MsgBox Err.Description
End Select
End Sub
Private Sub CommandButton1_Click()
On Error GoTo error_handler
Dim sname As String
Dim fname As String
Dim response As Integer
Dim length As Long
Dim wname As String
wname = "eligible.doc"
fname = "eligible.htm"
length = FileLen("\\PIRNWFS1\VOL1\GRPDATA\HELPDESK\Operations\foobar\" & fname)
ChangeFileOpenDirectory "\\PIRNWFS1\VOL1\GRPDATA\HELPDESK\Operations\Foobar\"
ActiveDocument.SaveAs FileName:=wname, AddToRecentFiles:=True
Commandbutton1.Delete
ActiveDocument.SaveAs FileName:=fname, FileFormat:=wdFormatHTML, AddToRecentFiles:=True
ActiveWindow.View.Type = wdWebView
response = MsgBox("File saved as '" & fname & "', do you want to close document?", vbYesNo, "GODS"
If response = vbYes Then
ActiveDocument.Close
End If
Exit Sub
error_handler:
Select Case Err.Number
Case 53
length = -1
Resume Next
Case Else
MsgBox Err.Description
End Select
End Sub