I want to save it back to the same name I opened. In that case do I need "fid". Also what does the "true" operand mean? Does it mean to save it?
Main Topics
Browse All TopicsI have opened an Excel file with:
Set myxl = CreateObject("Excel.Applic
Set wb = myxl.Workbooks.Open(fid)
What commands do I need to save and close it?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
wb.SaveCopyAs fid
wb.close false 'False is for cancel the changes since we already saved it
myxl.application.quit
set wb=nothing
set myxl = nothing
the savecopyas will overwrite any existing file in the same directory unless this file is open at the moment
if you want to make sure to not get any error from excel, insert:
myxl.displayalerts=false
Here is my code:
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdRun_Click()
fid = "WeeklyParts.xls"
Path = "C:\Documents and Settings\jerryc\My Documents\My Files\vb\MYstatus"
Call readitw(Path & "\" & fid)
Close #1
Close #2
Close #3
Close #4
MsgBox "done"
End Sub
Private Sub readitw(fid)
Dim myxl As Object
Set myxl = CreateObject("Excel.Applic
Set wb = myxl.Workbooks.Open(fid)
myxl.Sheets("sheet1").Sele
Open "file1.txt" For Output As #1
Open "file2.txt" For Output As #2
Open "file3.txt" For Output As #3
Open "file4.txt" For Output As #4
For i = 2 To 1000
partNumber = myxl.Cells(i, 1).Value
If partNumber = Null Then Exit For
ar = partNumber
partNumber = Right(partNumber, 5)
submitter = myxl.Cells(i, 2).Value
Version = myxl.Cells(i, 3).Value
ddd = myxl.Cells(i, 4).Value
Status = myxl.Cells(i, 5).Value
fixVersion = myxl.Cells(i, 6).Value
If fixVersion = Null Then fixVersion = ""
subsystem = myxl.Cells(i, 7).Value
Description = myxl.Cells(i, 8).Value
superceeded = myxl.Cells(i, 9).Value
If superceeded = Null Then
superceeded = ""
ElseIf Len(superceeded) < 5 Then
superceeded = ""
Else
superceeded = Right(superceeded, 5)
End If
associated = myxl.Cells(i, 10).Value
Keywords = myxl.Cells(i, 11).Value
If Status <> "Broken" & Status <> "Scrap" Then
If Keywords Like "*document*" Then
Key = "document"
Else
Key = ""
End If
Data = ar & Chr(1) & submitter & Chr(1) & Version & Chr(1) & ddd
Data = Data & Chr(1) & Status & " " & fixVersion & " " & superceeded
Data = Data & " " & Key & Chr(1) & Description & Chr(1) & "" & Chr(1)
Print #3, Data
Else
Print #1, Data
End If
If associated <> Null Then
Print #4, partNumber & " " & associated
End If
Next i
myxl.Application.DisplayAl
myxl.ActiveWorkbook.SaveAs
myxl.ActiveWorkbook.Close
myxl.Quit
Set myxl = Nothing
End Sub
I cannot reproduce it too on my computer
i recommend you try to comment out some lines and retest and see which line cause the problem
I also change the line
myxl.Application.DisplayAl
to
myxl.DisplayAlerts = False
myxl.ActiveWorkbook.SaveAs
myxl.ActiveWorkbook.Close
set wb = nothing
myxl.Quit
Set myxl = Nothing
ie
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdRun_Click()
fid = "WeeklyParts.xls"
Path = "C:\Documents and Settings\jerryc\My Documents\My Files\vb\MYstatus"
Call readitw(Path & "\" & fid)
Close #1
Close #2
Close #3
Close #4
MsgBox "done"
End Sub
Private Sub readitw(fid)
Dim myxl As Object
Set myxl = CreateObject("Excel.Applic
Set wb = myxl.Workbooks.Open(fid)
myxl.Sheets("sheet1").Sele
' Open "file1.txt" For Output As #1
' Open "file2.txt" For Output As #2
' Open "file3.txt" For Output As #3
' Open "file4.txt" For Output As #4
' For i = 2 To 1000
' partNumber = myxl.Cells(i, 1).Value
' If partNumber = Null Then Exit For
' ar = partNumber
' partNumber = Right(partNumber, 5)
' submitter = myxl.Cells(i, 2).Value
' Version = myxl.Cells(i, 3).Value
' ddd = myxl.Cells(i, 4).Value
' Status = myxl.Cells(i, 5).Value
' fixVersion = myxl.Cells(i, 6).Value
' If fixVersion = Null Then fixVersion = ""
' subsystem = myxl.Cells(i, 7).Value
' Description = myxl.Cells(i, 8).Value
' superceeded = myxl.Cells(i, 9).Value
' If superceeded = Null Then
' superceeded = ""
' ElseIf Len(superceeded) < 5 Then
' superceeded = ""
' Else
' superceeded = Right(superceeded, 5)
' End If
' associated = myxl.Cells(i, 10).Value
' Keywords = myxl.Cells(i, 11).Value
' If Status <> "Broken" & Status <> "Scrap" Then
' If Keywords Like "*document*" Then
' Key = "document"
' Else
' Key = ""
' End If
' Data = ar & Chr(1) & submitter & Chr(1) & Version & Chr(1) & ddd
' Data = Data & Chr(1) & Status & " " & fixVersion & " " & superceeded
' Data = Data & " " & Key & Chr(1) & Description & Chr(1) & "" & Chr(1)
' Print #3, Data
' Else
' Print #1, Data
' End If
' If associated <> Null Then
' Print #4, partNumber & " " & associated
' End If
' Next i
myxl.DisplayAlerts = False
myxl.ActiveWorkbook.SaveAs
myxl.ActiveWorkbook.Close
set wb = nothing
myxl.Quit
Set myxl = Nothing
End Sub
The following code leaves an excel.exe entry in the windows task manager:
Private Sub readitw(fid)
Dim myxl As Object
Set myxl = CreateObject("Excel.Applic
Set wb = myxl.Workbooks.Open(fid)
'myxl.Sheets("sheet1").Sel
myxl.DisplayAlerts = False
myxl.ActiveWorkbook.SaveAs
myxl.ActiveWorkbook.Close
Set wb = Nothing
myxl.Quit
Set myxl = Nothing
End Sub
In order to not have an excel.exe in windows task manager I had to change it to:
Private Sub readitw(fid)
Dim myxl As Object
Set myxl = CreateObject("Excel.Applic
'Set wb = myxl.Workbooks.Open(fid)
'myxl.Sheets("sheet1").Sel
myxl.DisplayAlerts = False
'myxl.ActiveWorkbook.SaveA
'myxl.ActiveWorkbook.Close
Set wb = Nothing
myxl.Quit
Set myxl = Nothing
End Sub
So, I can't even open the fid.
Business Accounts
Answer for Membership
by: JuergenHartlPosted on 2004-11-28 at 11:47:16ID: 12691220
wb.Close true, fid