+ Reply to Thread
Results 1 to 11 of 11

combine command button and a macro code

  1. #1
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    combine command button and a macro code

    I have a command button with this code.
    TST is a macro.
    I need to add 2 other macro with this command button.

    The names of the macro are:

    Button2_Click
    Save_Workbook

    How do I do it?

    Please Login or Register  to view this content.
    When i add the macro name as TST the I get this error.

    I have attached the screenshot of it.
    Attached Images Attached Images

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: combine command button and a macro code

    You did not post what the error message is, but the indication, based on the highlighted line of code, is that Excel has a problem with your File Name variable.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: combine command button and a macro code

    Thanks JLGWhiz,

    I am attching the screen shot of the error message.

    Please let me know if you require any more details.
    Attached Images Attached Images

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: combine command button and a macro code

    It is telling you that there is a problem with:
    1. File path
    2. File name
    3. File type, eg. .xlsm, .xlsx, .pdf, etc.
    4. Or file is corrupt.
    Check the data in cell Q42 to be sure it is accurate.

  5. #5
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: combine command button and a macro code

    Hey JLGWhiz,

    Thanks for your reply.

    If I assign that macro to a seperate button then everthing is perfect.

    But when i try to combine various macro with a command button then this error pops up.

    I am attaching my sample file incase that adds value.

    If I use the macro seperately then it works. Only if i combine then it does not work
    Attached Files Attached Files

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: combine command button and a macro code

    Strange that it works separately but not when called from another macro in the same workbook. The error message idicates that if the exported file is open it would not save to the PDF. But your statement that it works separately would belie that theory. I can't come up with a good answer for you, maybe somebody more techie than me would know the answer.

  7. #7
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: combine command button and a macro code

    does the folder "testing purpose" exist?
    Maybe you changed that as part of your testing between it working and not working.
    Last edited by scottiex; 02-04-2018 at 07:55 PM.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  8. #8
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: combine command button and a macro code

    Hey scottiex,

    Where did you see "testing purpose" folder ?

    The problem is that all the macro does not work when thet are combined with the command button.

    or else they work prefectly

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: combine command button and a macro code

    The value in C3 on the INVOICE sheet is tesing purpose\ which you use as part of the FullFileName variable. Nothing in your code creates a folder called "tesing purpose", which is why the code fails. If C3 is supposed to be part of the PDF file name, you need to remove that backslash at the end of the cell.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: combine command button and a macro code

    Hey xlnitwit,

    THANK YOU SO MUCH.

    works for me now.

    THANK you once again

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: combine command button and a macro code

    You're welcome. I was really just clarifying the point scottiex was making.

+ 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. [SOLVED] combine command button and a macro code
    By anilpatni1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2018, 12:53 PM
  2. VBA code to create command button. Print all sheets then delete command button.
    By Declamatory in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-15-2015, 05:18 PM
  3. [SOLVED] Code works in macro but not command button
    By datafiend in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-10-2014, 08:06 PM
  4. Macro Command Button: Combine Save As CSV and Delete Unsed Rows Macros
    By mustng_sally in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2013, 10:41 AM
  5. [SOLVED] code behind the command button that runs another macro
    By Vogelmann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2012, 06:04 AM
  6. Macro to create Command Button and assign code
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2011, 09:19 AM
  7. Code created in a Macro not working for a Command Button
    By Amber_D_Laws in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-13-2006, 06:40 PM

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