yitzle
Jun 15th, 2006, 12:03 AM
OK.
I can try to open, modify and close a XLS file, and create when it doesn't exist.
However, after modifying the XLS, when I open it, I need to do Window>Unhide>Unhide Workbook.
How do I fix that?
A Excel Macro reveals:
Windows("TimeLogger.xls").Visible = True
Please advise!
My code:
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim wkbBook As Excel.Workbook
Dim wkbObj As Excel.Workbook
Dim xlsfilename As String
xlsfilename = App.Path & "\TimeLogger.xls"
On Error GoTo create
Set wkbObj = GetObject(xlsfilename)
Dim i As Integer
i = 1
While wkbObj.Worksheets(1).Range("A" & i).Value <> ""
i = i + 1
Wend
wkbObj.Worksheets(1).Range("A" & i).Value = Format(Now, "mmmm-dd-yy")
wkbObj.Worksheets(1).Range("B" & i).Value = Format(Now, "h:nn")
wkbObj.Worksheets(1).Range("C" & i).Value = InputBox("Client?")
wkbObj.Worksheets(1).Range("D" & i).Value = InputBox("Description?")
wkbObj.Save
' Till now, all works. Unhide workbook!
Set xlApp = New Excel.Application
Set wkbNewBook = Workbooks.Open(xlsfilename)
wkbNewBook.Visible = True
wkbNewBook.Save
wkbNewBook.Close
Set wkbNewBook = Nothing
Set xlApp = Nothing
' End problem area
Exit Sub
create:
On Error Resume Next
Set xlApp = New Excel.Application
Set wkbNewBook = xlApp.Workbooks.Add()
wkbNewBook.Worksheets(1).Range("A1").Value = "a"
wkbNewBook.Close SaveChanges:=True, FileName:=xlsfilename
xlApp.Quit
Set wkbNewBook = Nothing
Set xlApp = Nothing
End Sub
I can try to open, modify and close a XLS file, and create when it doesn't exist.
However, after modifying the XLS, when I open it, I need to do Window>Unhide>Unhide Workbook.
How do I fix that?
A Excel Macro reveals:
Windows("TimeLogger.xls").Visible = True
Please advise!
My code:
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim wkbBook As Excel.Workbook
Dim wkbObj As Excel.Workbook
Dim xlsfilename As String
xlsfilename = App.Path & "\TimeLogger.xls"
On Error GoTo create
Set wkbObj = GetObject(xlsfilename)
Dim i As Integer
i = 1
While wkbObj.Worksheets(1).Range("A" & i).Value <> ""
i = i + 1
Wend
wkbObj.Worksheets(1).Range("A" & i).Value = Format(Now, "mmmm-dd-yy")
wkbObj.Worksheets(1).Range("B" & i).Value = Format(Now, "h:nn")
wkbObj.Worksheets(1).Range("C" & i).Value = InputBox("Client?")
wkbObj.Worksheets(1).Range("D" & i).Value = InputBox("Description?")
wkbObj.Save
' Till now, all works. Unhide workbook!
Set xlApp = New Excel.Application
Set wkbNewBook = Workbooks.Open(xlsfilename)
wkbNewBook.Visible = True
wkbNewBook.Save
wkbNewBook.Close
Set wkbNewBook = Nothing
Set xlApp = Nothing
' End problem area
Exit Sub
create:
On Error Resume Next
Set xlApp = New Excel.Application
Set wkbNewBook = xlApp.Workbooks.Add()
wkbNewBook.Worksheets(1).Range("A1").Value = "a"
wkbNewBook.Close SaveChanges:=True, FileName:=xlsfilename
xlApp.Quit
Set wkbNewBook = Nothing
Set xlApp = Nothing
End Sub