I am very new to all this technical stuff, but I am trying to format an excel spreadsheet via access vba but getting an error. Can some one please advice?
My code is: - Private Sub Command3_Click()
-
DoCmd.Hourglass True
-
DoCmd.SetWarnings False
-
'On Error GoTo ErrHandler:
-
' *************** RUN EUR RI DATA RECON ********************
-
-
Dim objXL As Object
-
Dim strWin As String
-
Dim sglRep As Single
-
Dim intPos As Integer
-
'Set newName = Sheets("Data")
-
'newName.Visible
-
-
strFile = "P:\test.xls"
-
-
If strFile = "" Then Exit Sub
-
-
'Saves changes and closes the speradsheet
-
Set objXL = GetObject(strFile)
-
objXL.Close savechanges:=True
-
-
'Transfers the data to the Excel tabs depending on the file being updated
-
'DoCmd.TransferSpreadsheet acExport, 8, "tbl_2004 UW Data", strFile, True, "2004 UWY"
-
DoCmd.TransferSpreadsheet acExport, 8, "test", strFile, True, "test"
-
-
-
-
Set objXL = GetObject(strFile)
-
objXL.Application.Visible = True
-
-
strWin = strFile
-
intPos = 1
-
-
'Finds name of window
-
Do Until intPos = 0
-
-
intPos = InStr(strWin, "\")
-
strWin = Right(strWin, Len(strWin) - intPos)
-
-
Loop
-
-
'Makes spreadsheet current and unhidden
-
objXL.Parent.Windows(strWin).Activate
-
objXL.Parent.Windows(strWin).Visible = True
-
-
'Sets file to read only
-
'If strFile = "P:\AgedDebtors\CashDataMaster.xls" Then
-
' objXL.Application.DisplayAlerts = False
-
' objXL.ChangeFileAccess Mode:=xlReadOnly
-
'Sheets("Data").Select
-
'Cells.Select
-
'Cells.EntireColumn.AutoFit
-
'Range("A1").Select
-
'Range("A1:R48").Sort Key1:=Range("O2"), Order1:=xlDescending, Header:= _
-
' xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
-
' DataOption1:=xlSortNormal
-
'End If
-
-
strFile = ""
-
strWin = ""
-
sglRep = 0
-
DoCmd.Hourglass False
-
DoCmd.SetWarnings True
-
-
Range("a:c").select
-
-
'MsgBox "Run Complete"
-
-
'ErrHandler:
-
'MsgBox (Err.Source & " - " & Err.Description)
-
End Sub
Thanks in advance.
2 1684
To use Linq's expression, Carnac the Magnificent is not available at this site, and we can't read your mind....LOL! Please provide more details. What is the error you are getting? Could the error be related to some of the code you have commented out?
Hi. I have added code tags before and after your code section, which makes it much easier to refer to specific lines.
As PDog has said, you really must tell us what is going wrong and what kind of error message you are getting - we should not be guessing.
As an observation, I can say for certain that the commented out code at lines 50-54 will not function reliably in Access, as you are not using the automation object variable you have defined (objXL) to communicate with the Excel instance. Referring to ranges and so on works within Excel itself without qualification by the worksheet object, but not when running as automation code from Access.
ALL references to ranges and so on will need to be qualified with the current object and worksheet variables. For example,
ObjXL.ActiveSheet.Range("A1").Select
and not
Range("A1").Select
As an aside, it is much more efficient not to select ranges and cells before setting them to specific values or formats; refer directly to the range or cell object to set its properties.
Many of these problems arise when using the Macro Recorder in Excel to record actions. The code recorded is neither truly portable when used in an automation context nor particularly efficient.
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bones |
last post by:
How can I import an Excel 97 spread sheet to Access 2.0?
I'm new to Access.
Bones
|
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...
|
by: com |
last post by:
Extreme Web Reports 2005 - Soft30.com
The wizard scans the specified MS Access database and records
information such
as report names, parameters and subqueries. ......
|
by: sparks |
last post by:
We get more and more data done in excel and then they want it imported
into access.
The data is just stupid....values of 1 to 5 we get a lot of 0's ok
that alright but 1-jan ?
we get colums...
|
by: pic078 via AccessMonster.com |
last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files)
that remains stuck in task manager after exiting the application - you can't
reopen database after exiting as a result...
| |
by: shenkel55 |
last post by:
I'm using Access and Excel 2003. Using either the import wizard or code, I have the same problem. This problem only happens with Excel files automatically generated by Corp IT. If I try to do an...
|
by: accessvbanewbie |
last post by:
I would like to export a recordset from access to excel but after each record is exported I want to insert a new row.
The first recordset does this ok. However, the second recordset onwards does not...
|
by: JFKJr |
last post by:
Hello everyone, the following Access VBA code opens an excel file and creates textboxes in a given range of cells dynamically. The code attaches "MouseUP" and "Exit" events to the textboxes (using...
|
by: Joe Humburg |
last post by:
Hi everyone,
Looking for some help or ideas, on the folloiwng problem.
Have an Access 2003 application that creates an Excel file containing
data from an Access parameter query. This is...
|
by: OzNet |
last post by:
I have a query (with calculated fields) in Access (2007) and the data changes depending on the dates and staff person selected. I need to produce a series of graphs based on the data in this query...
|
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...
| |
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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...
|
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...
|
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...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
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...
| |