Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Excel Crashes When Importing Data File

I've writen code to open up .dat extension files in excel, copy the 1st
worksheet of the dat workbook, and paste this worksheet as the last worksheet
into an Excel workbook that is essentially a database. The code then makes a
copy of this worksheet which is used to perform calculations and store
results and pastes it as the last worksheet. I'm some 323 worksheets into
assembling this database, and suddenly when I attempt to import new data,
Excel crashes. I would appreciate it if someone could take a look at the
relevant part of my code and give me some idea of what the problem is.

Thanks in advance,
Jason

Set Wka = Application.Workbooks("MPD.xls")

' Check to see if data already exists and give option to replace
newname = Typ & Dir & " " & Coating & " " & Grade & " " & Gage

For Each Wks In Wka.Worksheets
If Wks.Name = newname Then
Dim Msga, Msgb, Style, Title, Response
Msgb = newname & " data already exists. Do you want to replace the
data?"
Style = vbYesNo + vbQuestion + vbDefaultButton2
Title = "Replace Data?"

Response = MsgBox(Msgb, Style, Title)
If Response = vbYes Then
Application.DisplayAlerts = False
Wka.Sheets(newname).Visible = True
Wka.Sheets(newname + "R").Visible = True
Wka.Sheets(newname).Delete
Wka.Sheets(newname & "R").Delete
Application.DisplayAlerts = True
Else
GoTo Line1
End If
End If
Next Wks


Dim SourceBook As Workbook
Dim RetVal As Boolean

' Turn off screen updating.
Application.ScreenUpdating = False

' Show the Open dialog box.
RetVal = Application.Dialogs(xlDialogOpen).Show("*.dat")

' Set an object variable for the workbook containing the data file.
Set SourceBook = ActiveWorkbook

' Copy the 1st Workheet From Workbook "Sourcebook" and paste at _
the end of Workbook "Wka".
SourceBook.Worksheets(1).Copy after:=Wka.Worksheets(Worksheets.Count)

'Name the worksheet based on selections
Wka.Activate
Set Wks = ActiveSheet
Wks.Name = newname

' Close the book containing the text file.
SourceBook.Close SaveChanges:=False

'INSERT A COPY OF THE DATA SHEET TO BE USED FOR CALCULATIONS
Wks.Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = newname & "R"
Set ws = ActiveSheet
Wks.Visible = False



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default Excel Crashes When Importing Data File

Put the following line of code at the top of your module, if you don't
already have it:

Option Explicit

Then declare all variables and fix compiler errors.

Step into the code when the error occurs and let us know what line the
error occurs on.
I see a line of code "GoTo Line1", but I don't see any "Line1:" anywhere
in the program, for starters. When the code ends up on this line, is it
OK for the code to goto the very 1st line in the entire module and
restart there? This may not be what you want. Normally, a labeled line
would be something like:

If cond _
then
'Do something
else
Goto ContinueMyProcessing
end if

ContinueMyProcessing:
'Continue other processing here.
--
Regards,
Bill Renaud



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing text file data into excel GradStudent N need Excel Discussion (Misc queries) 1 September 7th 07 09:44 AM
Importing Data from another Excel File Pasha Excel Programming 1 January 25th 04 12:04 PM
Importing/querying data from .mdb file into Excel jimmy shaker. Excel Programming 5 January 11th 04 03:38 PM
Help with data importing from txt file to excel programmatically SUDHENDRA Excel Programming 2 December 7th 03 02:14 PM
Importing data from an Excel file on a web server using ADO/VBA Dean Frazier Excel Programming 0 November 13th 03 12:39 AM


All times are GMT +1. The time now is 12:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"