Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error 1004 (2000)

    ... possible cause of error 1004 when code go in:

    With ActiveWorkbook.PublishObjects.Add( _
    SourceType:=xlSourceRange, _
    fileName:=TempFile, _
    Sheet:=ActiveSheet.Name, _
    Source:=Selection.Address, _
    HtmlType:=xlHtmlStatic)
    .Publish (True)
    End With

    complete code:

    Sub INVIA_EMAIL_TESTO_TUTTI(MATRICOLA, FOGLIO)
    Dim MATRICOLA_S As String

    Worksheets("TEMPLATE_2").Select
    ULTIMA = Worksheets("TEMPLATE_2").Cells(Rows.Count, "A").End(xlUp).Row '+ 1

    If FOGLIO = "LUST10C" Or FOGLIO = "LUST091" Then
    Worksheets("TEMPLATE_2").Range("A1:U" & ULTIMA).Select
    Else
    Worksheets("TEMPLATE_2").Range("A1:Q" & ULTIMA).Select
    End If

    Set Source = Selection

    On Error GoTo errSend
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With OutMail

    MATRICOLA_S = "OI27461" & ";" & "OI32838"

    .To = MATRICOLA
    .CC = MATRICOLA_S 'MATRICOLA_S 'E_MAIL.PER_CONOSCENZA"
    .BCC = ""
    .Subject = "A.L.A. - ADEMPIMENTI LEGGE ANTIRICICLAGGIO" & " *** " & "TAB. - " & FOGLIO & " - " & Trim(Worksheets(FOGLIO).Range("C1")) '
    'If FOGLIO = "LUST091" Then
    .HTMLBody = STRBODYTEXT_1 & RangetoHTML
    'End If
    .Send 'OPPURE .Display

    End With

    Set OutMail = Nothing
    Set OutApp = Nothing

    Worksheets("TEMPLATE_2").Range("A1").Select

    Exit Sub

    errSend:

    MsgBox Err.Number & " : " & Err.Description

    End Sub



    Function RangetoHTML()

    Dim FSO As Object
    Dim TS As Object
    Dim TempFile As String
    TempFile = Environ$("temp") & "/" & _
    Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
    With ActiveWorkbook.PublishObjects.Add( _
    SourceType:=xlSourceRange, _
    fileName:=TempFile, _
    Sheet:=ActiveSheet.Name, _
    Source:=Selection.Address, _
    HtmlType:=xlHtmlStatic)
    .Publish (True)
    End With
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TS = FSO.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = TS.ReadAll
    TS.Close
    Set TS = Nothing
    Set FSO = Nothing
    Kill TempFile

    End Function

    tks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: error 1004 (2000)

    There are many undeclared variables in INVIA_EMAIL_TESTO_TUTTI, but when I declare them (and change some of the names to match the workbook), the code runs without error when I try it.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: error 1004 (2000)

    Your workbook has been set to use R1C1 style cell references instead of the more usual A1 style, in the General tab of Tools | Options. But Selection.Address returns an A1 style reference, and this causes the error. You can do one of the following:

    1) Clear the check box to use R1C1 references in the General tab of Tools | Options...

    or

    2) Change
    <code>
    Source:=Selection.Address, _
    </code>
    to
    <code>
    Source:=Selection.Address(ReferenceStyle:=xlR1C1), _</code>

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error 1004 (2000)

    Destroied!!!!!!!!!
    Attached test file a cannot solved my self, Help me, please..
    in other case accept a Good New Year.
    Sal.

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error 1004 (2000)

    ... sure this is the prob.
    But i can test tomorrow in my offce.
    Tks as usual.

Posting Permissions

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