473,657 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel Worksheets in Access VBA

1 New Member
Hi

I am trying to switch Excel worksheets in VBA. I get an error saying "subscript out of range". Please Help- Here is code (Fails on last 2 lines- Note that I ommited the recordset portion of code because it works):

Dim objXLApp As Object
Dim objXLws As Object

Dim strSDocPath As String 'Full path/name of template (Source) file
Dim strTPath As String 'Full path of (Target) file
Dim strTDocPath As String 'Full path/name of (Target) file


strSDocPath = "\\Saturn\Datab ases\Tracer\Tem plates\SigmaTem plate.xls"
strTPath = "C:\AccessExpor t"
strTDocPath = "C:\AccessExpor t\Sigma.xls"
strCurrentRunNo = [Forms]![frmRCESapphire]![RCErunno]
' Create the Excel object
Set objXLApp = CreateObject("E xcel.Applicatio n")

' Open the template workbook file
objXLApp.Workbo oks.Open (strSDocPath)

' Save the template as the file specified by the user
objXLApp.Active Workbook.SaveAs (strTDocPath)

' Select the Worksheet
Set objXLws = objXLApp.Active Workbook.Worksh eets("SIGMA")

' Activate the selected worksheet
objXLws.Activat e

' Ask Excel to copy the data from the recordset starting with Cell A5
objXLws.Range(" B2").Value = strCurrentRunNo
objXLws.Range(" B3").Value = Now()
objXLws.Range(" A6").CopyFromRe cordset rstSigmaExport

' Select the alternate worksheet
objXLApp.Worksh eets("Rates").A ctivate

' Activate the alternate worksheet
Set objXLws = objXLApp.Active Workbook.Worksh eets("Rates")
Aug 13 '08 #1
1 4854
janders468
112 Recognized Expert New Member
Just to rule this out quickly, are you sure that worksheet "Rates" exists (isn't misspelled or anything)? This is the error you get when you try to activate a non-existent worksheet.
Aug 14 '08 #2

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

Similar topics

13
35524
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate),
3
9237
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
11
4043
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000 for me) I of course thought that I mustn't be unloading a variable properly.
3
8649
by: deko | last post by:
This code runs okay, but I cannot quit Excel. I've read that this may be due to the way I reference the object variables, but I don't know how else I would reference them. How do I get Excel to quit gracefully? Thanks in advance. Set xlapp = GetObject(, "Excel.Application") 'create new on error if none exists Set xlwkb = xlapp.Workbooks.Open(strTarget)
1
1631
by: Steve Spittell | last post by:
Need some assistance, I am trying to take recordset from Access that contains Names; Name1 Name2 Name3 Name4, etc Open up an Excel Workbook and Create New Worksheets based on the names in the Recordset.
4
8703
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets within a single workbook with these records. I would end up with around 500 worksheets, 1 for each unique ID value. I was thinking this could be done if I have an exported flag column in the table, and I search for the max (or min) on the ID...
3
3999
by: dan_roman | last post by:
Hi, I developed a script with a nice interface in Tkinter that allows me to edit some formulas and to generate an Excel worksheet with VBA macros within it. The script runs perfectlly in Office 2000, but in Office 2003 crash at line: "wbc = workbook.VBProject.VBComponents.Add(1)" Please help me :-( the code of the module that crash is (only in Excel 2003, in 2000 not): import os
9
4541
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso TypeOf obj Is IDisposable Then DirectCast(obj, IDisposable).Dispose()
10
3112
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
0
1464
by: helraizer1 | last post by:
Hi folks, I have made a ledger sub in Excel. The task is to create a spreadsheet solution for a foreign exchange bureau so each transaction that happens it adds the details to a ledger sheet. For this I have this code: Sub ledge() Dim r As Excel.Range Dim i As Integer
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.