Results 1 to 8 of 8

Convert Code from using Userbox to Userform

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Convert Code from using Userbox to Userform

    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
    Last edited by bdb1974; 10-16-2009 at 12:46 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1