473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Error 91 - Object variable or With block variable not set

I am running a simple excel app within Access. I am opening a new workbook, adding data, formatting the sheet ect. It works quite well the first time I run it (click event). The next time it fails with "Error 91 - Object variable or With block variable not set". Here is the first part of the code and the location where it fails on the second try:

Private Sub CalcPercent_Click()

DELCLARATIONS:

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
Set xlWB = Nothing
Set xlWS = Nothing
Set xlApp = Nothing

GETFILE:

DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acExport, 8, "Huawei Pricing", "c:\Caten_McGuire\Export\3G_Supplier_Pricing_Expor t"
DoCmd.SetWarnings True

EXCELFORMAT:

Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Open("c:\Caten_McGuire\Export\3G_S upplier_Pricing_Export")
Set xlWS = xlWB.Worksheets("Huawei_Pricing")

INITIALFORMAT:
With xlWS
.Range("A1:AI1").Select
End With


With Selection.Interior **FAILS HERE**
.Pattern = xlSolid
.ThemeColor = xlThemeColorLight2
.TintAndShade = -0.499984740745262
End With

At the end of the routine I close this way:

Set xlWB = Nothing
Set xlWS = Nothing
Set xlApp = Nothing
Attached Files
File Type: docx Error_91.docx (12.2 KB, 432 views)
May 31 '12 #1
1 3362
dsatino
393 256MB
Weird... I had the same issue yesterday pertaining to 'with' and excel from within Access.

In any case, I think your failure is simpler. I think you need to move your "with Selection...." inside the 'With xlWS'.

Expand|Select|Wrap|Line Numbers
  1.  
  2. With xlWS
    .Range("A1:AI1").Select
  3. With Selection.Interior 
  4. .Pattern = xlSolid
  5. .ThemeColor = xlThemeColorLight2
  6. .TintAndShade = -0.499984740745262
  7. End WithEnd With
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
May 31 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: RJN | last post by:
Hi Sorry for posting again. I'm calling a shared method in the class. The following error is found in production though I'm not able to reproduce. ...
6
by: Neo Geshel | last post by:
I am trying to deal with an image in code-behind. I consistently get the following error: Server Error in '/' Application. Object variable or With block variable not set. Description: An...
3
by: Richard Hollenbeck | last post by:
I've marked the line in this subroutine where I've been getting this error. It may be something stupid but I've been staring at this error trying to fix it for over an hour. I'm pretty sure the...
9
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
5
by: mekon | last post by:
Hi All, I'm hoping someone out there can give me a hand with this problem I've got. I have an Access DB that people connect to using Access RT 2000. There are some machines that can connect...
1
by: abhijmenbumca07 | last post by:
Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
4
by: BrianAdev | last post by:
Why It throw an error of <Object variable or With block variable not set> set objAccess = GetObject(strMdbPath) objAccess.DoCmd.SetWarning False objAccess.DoCmd.OpenReport strReportName, 0 'It...
3
by: Newbie19 | last post by:
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message: Object variable or With block variable not set. Description: An unhandled...
5
by: Al G | last post by:
Hi, I'm converting a bit of POP3 VB6 code to VB2005, and have run into this error with the following code. Can someone help me find out what I'm missing/doing wrong? 'holds the attachments...
0
by: Paul Morriss | last post by:
I get this error from an application: ************** Exception Text ************** System.NullReferenceException: Object variable or With block variable not set. at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.