473,326 Members | 1,972 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,326 software developers and data experts.

Automation error

Hello everyone I have this code but i keep getting Automation error. what Im tritng to accomplish is a marco that will copy worksheets into a summary and not remove the source in the orginal file


All my workbook have data all on sheet one all have the same headings all. and all in the same folder Someone please help...
Option Explicit

'Combine Workbooks
'By Tommy Miles
'This sample goes through all the Excel files in a specified directory and combines theminto
'a single workbook. It renames the sheets based on the name of the original workbook:
Sub CombineWorkbooks()
Dim CurFile As String, DirLoc As String
Dim DestWb As Workbook
Dim ws As Object 'allows for different sheet types

DirLoc = ThisWorkbook.path & "\tst\" 'location of files
CurFile = Dir(DirLoc & "*.xls")

Application.ScreenUpdating = False
Application.EnableEvents = False

Set DestWb = Workbooks.Add(xlWorksheet)

Do While CurFile <> vbNullString
Dim OrigWb As Workbook
Set OrigWb = Workbooks.Open(filename:=DirLoc & CurFile, ReadOnly:=True)

' Limit to valid sheet names and remove .xls*
CurFile = Left(Left(CurFile, Len(CurFile) - 5), 29)

For Each ws In OrigWb.Sheets
ws.Copy After:=DestWb.Sheets(DestWb.Sheets.Count)

If OrigWb.Sheets.Count > 1 Then
DestWb.Sheets(DestWb.Sheets.Count).Name = CurFile & ws.Index
Else
DestWb.Sheets(DestWb.Sheets.Count).Name = CurFile
End If
Next

OrigWb.Close SaveChanges:=False
CurFile = Dir
Loop

Application.DisplayAlerts = False
DestWb.Sheets(1).Delete
Application.DisplayAlerts = True

Application.ScreenUpdating = True
Application.EnableEvents = True

Set DestWb = Nothing

End Sub
Oct 28 '11 #1
2 1836
Rabbit
12,516 Expert Mod 8TB
It would help to know what line the error is on.
Oct 28 '11 #2
Stewart Ross
2,545 Expert Mod 2GB
Unless you have object variable ThisWorkbook defined globally it is certainly not defined or set in line #4:

Expand|Select|Wrap|Line Numbers
  1. DirLoc = ThisWorkbook.path & "\tst\" 'location of files
As Rabbit said, it helps to know what line the error is on.

-Stewart
Oct 28 '11 #3

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

Similar topics

17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
2
by: Andante.in.Blue | last post by:
Our Access 97 database is a single-file (non-splitted, pure Access) hosted no a network server, accessed regularly by a handful of users around the office. Until recently (until the Great...
1
by: JC | last post by:
I am getting a "Compile Error: Automation Error" with this function and I can't figure out why. Can anyone help? The error hits as soon as the function is recognized. Function...
1
by: Lisa | last post by:
Can anyone help me with an "Automation Error" I am receiving in Access XP? I am using the Combo Box wizard to create a combo box on a simple form and receive the following error "Automation Error....
6
by: Tremendo | last post by:
Hi, I have two PCs: PC1: Visual Studio 2005 (including .NET framework 2.0. PC2: Visual Studio 6 (using Visual Basic 6) + .NET framework 2.0 installed separately. On PC1 I wrote and built a C#...
1
by: Bruce | last post by:
Hello, I know this must be something simple I'm overlooking but I can't get err.raise inside a class to return anything but 440 - automation error. For example, if I create the following test...
5
by: smdupont | last post by:
Hi everyone! I am brand new to the Access world. I have downloaded files for a data base that I will use with my new job to my computer. The data base tables and information is working great. ...
1
by: =?Utf-8?B?VGVycnk=?= | last post by:
Hi all, I am trying to access a .net assembly from VB6. I have created the . Net assembly, exposed it to COM and registered it. I am able to add a reference to it in my VB6 project. When I...
5
by: nikhilkajrekar | last post by:
For Each objObj In .CurrentProject.AllForms DoEvents intObj = intObj + 1 .DoCmd.OpenForm objObj.Name, acDesign, , , , acHidden Set objForm = .Forms(objObj.Name) With...
5
by: ricovox | last post by:
Hello, Every time I try to create an ADODB.Connection object, I receive the following error: ----------- Runtime Error '-2147024703 (800700c1)': Automation error %1 is not a valid Win32...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.