Print or Save Excel UserForm as PDF file during run time using VBA

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ธ.ค. 2024

ความคิดเห็น • 32

  • @ahsing_excel_VBA
    @ahsing_excel_VBA  5 หลายเดือนก่อน

    Known issues:
    1. Error where variable is not defined. Suggestion: Delete the newly created blank sheet, save your workbook, close and reopen it. Then, run the code again. If the error persists, add 'ws.Select' before 'ws.Paste' and check the second point.
    2. PDF file gets corrupted when opened. Suggestion: Add the parameter 'ActivePrinter:="Microsoft Print to PDF"' before 'PrToFileName' so that Excel will convert the file to PDF for you.
    Hope you find this information useful. Thanks for watching and have a wonderful day!

  • @Elizabeth-qp3uj
    @Elizabeth-qp3uj 3 หลายเดือนก่อน

    Thanks for this quick & easy manner macro. If you could help me with a current issue:
    Sometimes, not always, the screenshot is not of the Userform, but rather something else on the PC screen. This happens only to the users running Windows 11, not an issue with those of us using Windows 10. I added a loop of 10 'DoEvents' and now the occurrence happens less often, but I really need it to not ever grab the wrong screenshot. Is there anything else to do to ensure the focus is on the Userform? Thank you!

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  3 หลายเดือนก่อน +1

      My pleasure. Regarding your issue, I'm not sure if you can try the 'SetFocus' method. Setting focus on any control on the UserForm may help the macro better detect the desired window. I hope this helps. Thanks for watching, and I wish you a wonderful day!

    • @Elizabeth-qp3uj
      @Elizabeth-qp3uj 3 หลายเดือนก่อน

      @@ahsing_excel_VBA Thank you, that's an easy fix and great idea. Thank you for your help. May your day be wonderful too.

    • @Elizabeth-qp3uj
      @Elizabeth-qp3uj 2 หลายเดือนก่อน

      Shame, I had to drop this macro from my process since I couldn't get it to consistently screenshot the worksheet.
      I thought SetFocus would work, but it didn't. I added in loops of DoEvents and still had issues.
      My users were unhappy and I was frustrated putting out fires. Worked well on my Windows 10 PC, but inconsistent on Windows 11.

  • @mazenzagha8811
    @mazenzagha8811 ปีที่แล้ว

    Thanks again and again sir sir you are gentle 😊😊😊😊😊😊❤❤❤❤❤

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  ปีที่แล้ว +1

      My pleasure 😉
      Glad you like it. Thanks for watching and have a nice day.

    • @mazenzagha8811
      @mazenzagha8811 ปีที่แล้ว +1

      sir i have a massage when i run the program " the massage is
      acrobat reader could not open the file ,because either note supported type or beacause the file damaged ( it was sent as e-mailattached ,and was not correctly decoded "
      pls sir how solve this matter
      @@ahsing_excel_VBA

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  ปีที่แล้ว +1

      Hi. May I know if the problem arises during runtime or when you open the file? It seems like the file format is incorrect.

    • @mazenzagha8811
      @mazenzagha8811 ปีที่แล้ว

      @@ahsing_excel_VBA sir thank you for replying me .
      Sir could you please send your email to send you the file to check it.seince i try many times and couldn't.pls sir

    • @mazenzagha8811
      @mazenzagha8811 ปีที่แล้ว

      @@ahsing_excel_VBA sir when i open the file pdf

  • @phole7591
    @phole7591 10 หลายเดือนก่อน

    I following your coding but when I click on the newly created PDF, got an error "Not supported file type or damage .. not decode correctly". Can you help and give some pointers ? Thanks

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  10 หลายเดือนก่อน

      Hi. Your situation resembles Mazen's. It's likely due to the PDF opener.
      My suggestions were:
      1. Ignore the very first error and rerun the macro again.
      2. Try attempt to open the file using Microsoft Edge.
      3. Alternatively, you might want to consider his solution, which involved converting the sheet to a PNG file instead of PDF. You can find more details in this video: th-cam.com/video/9qtl7AL9_GM/w-d-xo.html.
      Additionally, if you'd like me to gain a better understanding of your issue, consider recording your screen from start to finish and sending it to me via Gmail or Facebook private message.
      Hope one of them help.
      Thanks for watching and have a nice day.

  • @nachiketbhale6150
    @nachiketbhale6150 6 หลายเดือนก่อน

    i copied as it is VBA code but when i run the same , getting error as Variable not defined

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  6 หลายเดือนก่อน

      Hi, you can add a line to define the variable first.

    • @nachiketbhale6150
      @nachiketbhale6150 6 หลายเดือนก่อน

      I tried to add as
      Dim WS as Worksheet
      Is it correct?

    • @nachiketbhale6150
      @nachiketbhale6150 6 หลายเดือนก่อน

      @@ahsing_excel_VBA What line i need to add as variable, Can you provide me the line , It will help me

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  6 หลายเดือนก่อน

      yup. It is correct.

  • @nachiketbhale6150
    @nachiketbhale6150 6 หลายเดือนก่อน

    i am getting error WS variable not defined - any one can help me

    • @ahsing_excel_VBA
      @ahsing_excel_VBA  6 หลายเดือนก่อน

      Did you notice a new worksheet was added? If so, delete the new worksheet and run it again. It should be fine then.

    • @nachiketbhale6150
      @nachiketbhale6150 6 หลายเดือนก่อน

      Yes every time new worksheet is getting created as blank