+ Reply to Thread
Results 1 to 16 of 16

Run time-13 error

  1. #1
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Run time-13 error

    Hello,

    I'm trying to update a VBA that was written by someone else (see below), and I'm getting a run-time 13 error.

    Please Login or Register  to view this content.
    The argument I'm getting error on is line the "If Len(PathToBody) > 0"

    Any suggestions?

    Thanks!
    Last edited by Leith Ross; 03-20-2014 at 02:35 PM. Reason: Added Code Tags

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    Hi and welcome to the forum...According to the forum rules it's a good possibility that the moderators may want you to put your code in code tags. You can check the forum rules on how to accomplish that. I just thought I would let you know before they do.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    Run-time 13 is pretty generic....can you tell me what the verbage in the error is? And what/where is PathToBody set?

  4. #4
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Run time-13 error

    The run time error is "type mismatch". PathToBody:="C:\Users\XXXXXX\Desktop\Test.docx"

    Thanks for any help you can provide!

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    how is BodyMarker dimensioned?

  6. #6
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Run time-13 error

    The code says "Dim BodyMarker As String".

  7. #7
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    can I see more of the code?

    Please Login or Register  to view this content.
    this seems weird to me.....maybe PathToBody = "C:\Users\XXXXXXX\Desktop\Test.docx"

  8. #8
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Run time-13 error

    Here is the full code...

    Ideally what I'm trying to do is replace the commands for LotusNotes with commands for Outlook. For privacy reasons, I've redacted some of the indentifiable information, namely the email address to which the test email would be sent and the file path where the files are found.

    I don't know if what I'm attempting to do is possible as everything I've read says the conversion from LotusNotes to Outlook is complicated, and I'm pretty novice, but any help you can provide will be very appreciated.

    Thanks!

    ----------------------------------------------------------------------------------------------------------------------

    Function ComposeEmailInLotusNotes(Optional ByVal SendToArray As Variant, _
    Optional ByVal Subject As Variant, _
    Optional ByVal PathToBody As Variant, _
    Optional ByVal PathToDisclaimer As Variant, _
    Optional ByVal CopyToArray As Variant, _
    Optional ByVal BlindCopyToArray As Variant, _
    Optional ByVal AttachmentFileArray As Variant) As Boolean

    'On Error GoTo ErrHandler

    Dim I As Long
    Dim Msg As String
    Dim Session As Object
    Dim UserName As String
    Dim MailDbName As String
    Dim MailDb As Object
    Dim MailDoc As Object
    Dim AttachME As Object
    Dim EmbedObj As Object
    Dim Workspace As Object
    Dim UIDoc As Object
    Dim WordApp As Object, WordDoc As Object
    Dim BodyMarker As String, DiscMarker As String

    'Create a Lotus Notes Session
    Set Session = CreateObject("Notes.NotesSession")

    'Get the Lotus Notes UserName
    UserName = Session.UserName

    'Construct the MailDbName from the UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    Set MailDb = Session.GETDATABASE("", MailDbName)

    'If Lotus Notes is not already open, open it
    If MailDb.IsOpen = False Then
    MailDb.OPENMAIL
    End If

    'Create New Email
    Set MailDoc = MailDb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    If Len(PathToBody) > 0 Then BodyMarker = "Body_Goes_Here"
    If Len(PathToDisclaimer) > 0 Then
    DiscMarker = "Disc_Sig_Go_Here"
    Else
    MsgBox "File Containing Disclaimer Message not Selected. Please Select File and Retry.", vbOKOnly + vbCritical, "Warning!"
    GoTo ErrHandler
    End If

    'Populate the recipients
    If Not VBA.IsMissing(SendToArray) Then MailDoc.SendTo = SendToArray
    If Not VBA.IsMissing(CopyToArray) Then MailDoc.CopyTo = CopyToArray
    If Not VBA.IsMissing(BlindCopyToArray) Then MailDoc.BlindCopyTo = BlindCopyToArray

    'Populate the Subject & Body of the Email
    If Not VBA.IsMissing(Subject) Then MailDoc.Subject = Subject
    If Not VBA.IsMissing(PathToBody) Then MailDoc.Body = BodyMarker & vbCrLf & vbCrLf & DiscMarker Else MailDoc.Body = DiscMarker
    MailDoc.Save True, False

    'Add attachments, if any
    If Not VBA.IsMissing(AttachmentFileArray) Then
    If Not VBA.IsArray(AttachmentFileArray) Then
    Call MsgBox("Attachments must be passed as an array.", vbExclamation, "Error")
    Else
    For I = LBound(AttachmentFileArray) To UBound(AttachmentFileArray)
    If FileFolderExists(CStr(AttachmentFileArray(I))) Then
    Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment" & I)
    '1454 indicates a file attachment
    Set EmbedObj = AttachME.EMBEDOBJECT(1454, "Attachment" & I, AttachmentFileArray(I), "") 'Required File Name
    Else
    Call MsgBox("Attachment file does not exist at: " & AttachmentFileArray(I) & ". Press OK to continue.", vbExclamation, "Error")
    End If
    Next I
    End If
    End If

    'Specify that the email should be saved to the Database
    'Specify the posted date, otherwise the email will not get saved
    MailDoc.PostedDate = Now()
    MailDoc.SAVEMESSAGEONSEND = True

    'Create a Worksapce to hold the email
    Set Workspace = CreateObject("Notes.NotesUIWorkspace")
    Set UIDoc = Workspace.EDITDOCUMENT(True, MailDoc)

    With UIDoc
    'Find The Marker Text in the Body Item
    .GOTOFIELD ("Body")

    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = False

    If Len(PathToBody) > 0 Then
    .FINDSTRING BodyMarker
    'Open the Word document containing Body Text
    Set WordDoc = WordApp.Documents.Open(PathToBody)
    'Copy all contents to clipboard
    With WordApp.Selection
    .WholeStory
    .Copy
    End With
    'Paste Body into the Email
    .Paste
    WordDoc.Close SaveChanges:=False
    Set WordDoc = Nothing
    End If

    .FINDSTRING DiscMarker
    'Open the Disclaimer Signature Word document
    Set WordDoc = WordApp.Documents.Open(PathToDisclaimer)
    'Copy all contents to clipboard
    With WordApp.Selection
    .WholeStory
    .Copy
    End With
    'Paste Disclaimer into Email
    .Paste
    Application.CutCopyMode = False
    WordApp.Quit SaveChanges:=False
    Set WordApp = Nothing
    Set WordDoc = Nothing

    End With

    'Varun's Historical Code - Similar to above
    ' 'Open the Workspace and put the cursor in the Body of the email
    ' Call Workspace.EDITDOCUMENT(True, MailDoc).GOTOFIELD("Body")
    ' Call Workspace.RELOADWINDOW

    'Exit function successfully
    Set Session = Nothing
    Set MailDb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set EmbedObj = Nothing
    Set Workspace = Nothing

    On Error GoTo 0

    ComposeEmailInLotusNotes = True

    Exit Function

    ErrHandler:

    Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description
    MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext

    Set Session = Nothing
    Set MailDb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set EmbedObj = Nothing
    Set Workspace = Nothing

    ComposeEmailInLotusNotes = False

    On Error GoTo 0

    End Function
    ____________________________________________________________________________________________________________________________
    Sub avtest()

    Dim attachment As Variant

    ReDim attachment(1)
    attachment(1) = "C:\Users\XXXXXX\Desktop\Test Attachment.pdf"
    Call ComposeEmailInLotusNotes(SendToArray:="[email protected]", Subject:="Test", _
    PathToBody:="C:\Users\XXXXXX\Desktop\TestBody.docx", PathToDisclaimer:="C:\Users\XXXXXX\Desktop\DiscSig.docx", _
    CopyToArray:="[email protected]", BlindCopyToArray:="[email protected]", AttachmentFileArray:=attachment)


    End Sub

  9. #9
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    this is starting to make more sense....in the Sub Avtest did you write this part?....I'm not familiar with Lotus Notes, I would be curious if you took the PathToBody:= out of the Call ComposeEmailInLotusNotes, but just on that....it probably works like that but I haven't seen it and like I said I'm not a Lotus Notes expert....

  10. #10
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Run time-13 error

    So, as far as I can tell, the PathtoBody part gives the file where the body of the particular email is stored, so I'm hesitant to remove it. I did not write any of this code, but I'm trying to interpret it and, ultimately, see if I can modify it.

  11. #11
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    I understand....I don't want you to remove the whole thing, just the "PathToBody:=" part.....normally when you call a sub/procedure/FN that has parameters they determined by the position in the call...I suppose it is possible to "declare" them in the call to match what the procedure expects....so I was just curious what would happen....you can always put it back if it doesn't fix the issue....

  12. #12
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Run time-13 error

    So I tried removing it and still got the error...

  13. #13
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    I'm sorry, I have no idea on this one....I'll put a link into the "Call in the Cavalry" area see if someone else has any ideas....sorry again....

  14. #14
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    So I added this to another forum that might be able to help.....

    On a side note: in post #8 you might want to edit the code with code tags....the MODS can be touchy about that....and it hold the indenting formatting, which makes it easier to read for us helpers....sorry I wasn't able to help....

  15. #15
    Registered User
    Join Date
    03-20-2014
    Location
    Detroit, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Run time-13 error

    Thanks for your assistance!

  16. #16
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Run time-13 error

    No Problem....we did find out what it isn't...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  2. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  3. Replies: 7
    Last Post: 05-15-2013, 09:02 AM
  4. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  5. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM

Tags for this Thread

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