+ Reply to Thread
Results 1 to 6 of 6

Execution Error when calling a sub statement

  1. #1
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Execution Error when calling a sub statement

    Hello,

    I have 3 sub statements here.
    1.Sub Publish_PDF ()
    2.Sub Create_Report_Email()
    3.Sub Mail_Report()

    The first one (1) calls for the defined range to be published as a PDF. The second (2) calls for the first (1) to be attached to an outlook email with all fields populated after the first Sub is executed. And the third (3) is just a combination of both the first (1) and the second (2)ones with no additional details in the code, although it is really another version of the second one, because the second one does also create the PDF file.

    Upon execution, the first and the third ones are working properly. Not as used together but if I execute them individually. They will do as coded. However, when I execute the second one, which is ultimately the same as the third one but instead of writing the whole first (1) Sub, I just called it as in
    Please Login or Register  to view this content.
    before adding the last part of code with the outlook to complete the code, I get an error on as highlighted below.

    Call PDF.PNG

    My guess is that Calling the Sub doesn't necessarily link it to the remaining of the code, hence it does not execute properly.

    Do I need to add more things in the code for the whole code to sync or it has to be written as in the third sub statement?

    Thank you.

    1.Publish_PDF ()
    Please Login or Register  to view this content.
    2.Create_Report_Email()
    Please Login or Register  to view this content.
    3.Mail_Report()
    Please Login or Register  to view this content.
    Last edited by rakotonirinas; 06-13-2019 at 11:00 AM.

  2. #2
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Execution Error when calling a sub statement

    Anyone can give some indication here? Much appreciated.

  3. #3
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Execution Error when calling a sub statement

    Anyone could help please?

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Execution Error when calling a sub statement

    You have PDFFile declared in each routine. That means you have three separate variables that are not related to each other in any way, but your last sub needs the value set by the second one. Simple fix is to remove this part from the end of those two routines' declaration lines:

    Please Login or Register  to view this content.
    and add:

    Please Login or Register  to view this content.
    to the top of the module before any subroutines. (I"m assuming the code is all in the same module)
    Rory

  5. #5
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Execution Error when calling a sub statement

    This has done it. Thanks Rorya.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Execution Error when calling a sub statement

    Glad to help.

+ 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. VBA - Execution error
    By Black-Rabbit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2019, 12:45 PM
  2. [SOLVED] Execution error 1004
    By SIMBAtheCAT in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-25-2014, 10:55 AM
  3. [SOLVED] VBA Code Error Upon Execution
    By MacroMan87 in forum PowerPoint Programing
    Replies: 4
    Last Post: 09-21-2013, 01:28 AM
  4. VBA error during execution at Exit Sub
    By sportsguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2013, 01:32 PM
  5. Execution error 91
    By afortes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2010, 07:00 AM
  6. Error execution Report
    By pierre08 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-28-2010, 05:21 AM
  7. calling cells that don't = 0, without if statement
    By lovethepirk in forum Excel General
    Replies: 3
    Last Post: 12-15-2009, 11:19 PM

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