Hi all,
I'm trying to convert some code to run from a userbox to run from a userform
So far everything that I've tried I'm getting an error for something.
Directly below is the code I'm running initally.
(Good code )
Sub EXCEL_TO_HTML_RANGE()
Dim path As String
Dim Rng As Range
'Const stPath As String = "L:\Elec Dept Projects\MATERIALS\TMP"
Dim stPath As String
stPath = "L:\Elec Dept Projects\RELEASED FOR CONSTRUCTION\" & Sheets("BOM").Range("O2").Value & " " & Sheets("BOM").Range("O3").Value & " " & "-" & " " & Sheets("BOM").Range("O4").Value & "\"
path = stPath & Sheets("BOM").Range("O2").Value & "_BOM_copy.htm"
Dim Raddress As Range, strAddress As String
Set Raddress = Application.InputBox("Select your range to print by placing your mouse pointer over a starting cell box. Left click and hold while moving your pointer to the last desired cell. Then choose OK to Print or Cancel to Stop.", Type:=8)
strAddress = Raddress.Address
'rng = Range("O23").Value
'Set Raddress = str.Address
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, path, "BOM", _
Raddress.Address, xlHtmlStatic, "TABLE", "Materials List For Job:" & vbCrLf & Sheets("BOM").Range("O2").Value & " " & Sheets("BOM").Range("O3").Value & " " & "-" & " " & Sheets("BOM").Range("O4").Value)
.Publish (True)
.AutoRepublish = False
End With
End Sub
This is the codec coverted code that failing and I have yet to get it to work.
Private Sub CommandButton2_Click()
Dim path As String
Dim Rng As Range
Dim addr As Range
'Const stPath As String = "L:\Elec Dept Projects\MATERIALS\TMP"
Dim stPath As String
stPath = "L:\Elec Dept Projects\RELEASED FOR CONSTRUCTION\" & Sheets("BOM").Range("O2").Value & " " & Sheets("BOM").Range("O3").Value & " " & "-" & " " & Sheets("BOM").Range("O4").Value & "\"
path = stPath & Sheets("BOM").Range("O2").Value & "_BOM_copy.htm"
Dim Raddress As Range, strAddress As String
' Set Raddress = Application.InputBox("Select your range to print by placing your mouse pointer over a starting cell box. Left click and hold while moving your pointer to the last desired cell. Then choose OK to Print or Cancel to Stop.", Type:=8)
'Set Raddress = Cells(15, 23)
'strAddress = Raddress.Address
' strAddress = UserForm1.RefEdit1.Text
Set Raddress = UserForm1.RefEdit1
strAddress = Raddress.Address
'rng = Range("O23").Value
'Set Raddress = addr
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, path, "BOM", _
Raddress.Address, xlHtmlStatic, "TABLE", "Materials List For Job:" & vbCrLf & Sheets("BOM").Range("O2").Value & " " & Sheets("BOM").Range("O3").Value & " " & "-" & " " & Sheets("BOM").Range("O4").Value)
.Publish (True)
.AutoRepublish = False
End With
UserForm1.Hide
End Sub
the following give a "mismatch" error
Set Raddress = UserForm1.RefEdit1.Text
The following changes tell me an object is required.
Private Sub CommandButton2_Click()
Dim path As String
Dim Rng As Range
Dim addr As Range
'Const stPath As String = "L:\Elec Dept Projects\MATERIALS\TMP"
Dim stPath As String
stPath = "L:\Elec Dept Projects\RELEASED FOR CONSTRUCTION\" & Sheets("BOM").Range("O2").Value & " " & Sheets("BOM").Range("O3").Value & " " & "-" & " " & Sheets("BOM").Range("O4").Value & "\"
path = stPath & Sheets("BOM").Range("O2").Value & "_BOM_copy.htm"
Dim Raddress As Range, strAddress As String
' Set Raddress = Application.InputBox("Select your range to print by placing your mouse pointer over a starting cell box. Left click and hold while moving your pointer to the last desired cell. Then choose OK to Print or Cancel to Stop.", Type:=8)
'Set Raddress = Cells(15, 23)
'strAddress = Raddress.Address
' strAddress = UserForm1.RefEdit1.Text
Set strAddress = UserForm1.RefEdit1.Text ' info in userfor is same as in Cells(16, 23).Value
Raddress = strAddress
'rng = Range("O23").Value
'Set Raddress = addr
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, path, "BOM", _
Raddress.Address, xlHtmlStatic, "TABLE", "Materials List For Job:" & vbCrLf & Sheets("BOM").Range("O2").Value & " " & Sheets("BOM").Range("O3").Value & " " & "-" & " " & Sheets("BOM").Range("O4").Value)
.Publish (True)
.AutoRepublish = False
End With
UserForm1.Hide
End Sub
If anyone can correct this that would be great.
Thanks,
BDB
Bookmarks