I have a Run Time Error 91 for an Excel Add In

0 votes

I spent hours trying to debug this. This is a a macro to generate PDF from my selected cells. This code works on my personal workbook but when I export it as an add-in, add it in the developer tab and review the code again in the add-in workbook I keep getting an run time error 91: object variable or with block variable not set. Any help will be appreciated!

Sub Save_Selection_As_PDF_sheet()

Dim my_file As String


With ActiveSheet.PageSetup
            .LeftMargin = Application.InchesToPoints(0)
            .RightMargin = Application.InchesToPoints(0)
            .TopMargin = Application.InchesToPoints(0)
            .BottomMargin = Application.InchesToPoints(0)
            .HeaderMargin = Application.InchesToPoints(0)
            .FooterMargin = Application.InchesToPoints(0)
            '.Orientation = xlLandscape
            .Orientation = xlPortrait
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = False
            .PrintArea = Selection.Address
    Debug.Print I
    End With

Mar 25, 2022 in Database by Edureka
• 13,690 points
19,975 views

1 answer to this question.

0 votes

"Runtime Error 91: Object variable or with block variable not set" is a runtime error that can happen on any Windows-based operating system version. The DCOMCnfg.exe file, which is frequently used to establish rights and set system-wide security settings, is usually the problem.

When this file becomes corrupted or other problems emerge, the programme becomes unusable, and Runtime Error 91 appears on the screen. However, there could be other causes for the problem, and we'll look at all the options for resolving Runtime Error 91.

Variable problems could be the result of file corruption. Users could utilise the built-in SFC scan to fix the faulty data in the system files. This procedure, however, will not work if the corrupted files are not those of Windows, but rather those of an external application, even if it is one of the PC's main programmes. As a result, you should attempt reinstalling the software that is causing the Runtime Error 91.

Enter Control Panel into the Windows search box and press Enter.
Navigate to Programs > Remove a software from your computer
Select the programme from the list, right-click, and select Uninstall

Reinstall the problematic app

answered Mar 30, 2022 by gaurav
• 23,260 points

Related Questions In Database

0 votes
1 answer

I have to convert utc time to ist in excel

There are no built-in functions for determining ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,690 points
19,389 views
0 votes
1 answer

Can I have multiple primary keys in a single table?

A Table can have a Composite Primary Key which ...READ MORE

answered Oct 25, 2018 in Database by Frankie
• 9,830 points
3,858 views
0 votes
1 answer

showing an error in a MySQL trigger

use this code: CREATE TRIGGER sample_trigger_msg ...READ MORE

answered Sep 27, 2019 in Database by Omaiz
• 560 points
2,608 views
0 votes
1 answer

Unable to import data in excel from another website using VB code

Replace : Set ieTable = ieDoc.all.Item("report-table") With: Set ieTable = ...READ MORE

answered Sep 21, 2022 in Others by narikkadan
• 63,600 points
805 views
0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
911 views
0 votes
1 answer

I have a problem with counta function in VBA

When the worksheet name has a space, ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
1,104 views
0 votes
1 answer

Excel VBA - Subscript Out of Range Error (Run Time: Error 9)

Set rangePartner = Range(Partner.Cells(2, 2), Partner.Cells(2, 2).End(xlDown)) Needs ...READ MORE

answered Jan 21, 2023 in Others by narikkadan
• 63,600 points
1,037 views
0 votes
1 answer

I have a Run Time Error 91 for an Excel Add In

When there was no unhidden workbook open ...READ MORE

answered Apr 6, 2022 in Database by gaurav
• 23,260 points
978 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23, 2022 in Database by gaurav
• 23,260 points
860 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP