I have a an Excel workbook with two worksheets. One contains two charts/graphs and the other contains the data used as the basis for the charts. Opening this file displays both worksheets and allows editing without problems.
I wrote some VBA to make a copy of the workbook under a new name, then update the data. This works perfectly BUT when the new file is opened, the relevant workbook is hidden. I can unhide it manually and everything has been updated correctly, I just don't know why it's being hidden in the first place.
By a process of elimination, I know the actual work done inside the open sheet isn't causing the problem, so I've cut out those lines of code. Something in the following is the issue, but I'll be damned if I can see what.
I've used this code, or some version thereof, on many occasions with Office 2003 and not had any problems. I'm now using 2007, if that makes any difference. Any ideas?
I wrote some VBA to make a copy of the workbook under a new name, then update the data. This works perfectly BUT when the new file is opened, the relevant workbook is hidden. I can unhide it manually and everything has been updated correctly, I just don't know why it's being hidden in the first place.
By a process of elimination, I know the actual work done inside the open sheet isn't causing the problem, so I've cut out those lines of code. Something in the following is the issue, but I'll be damned if I can see what.
I've used this code, or some version thereof, on many occasions with Office 2003 and not had any problems. I'm now using 2007, if that makes any difference. Any ideas?
Code:
Private Sub Command49_Click()
Dim strSQL As String
Dim Rst As Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim strCell As String
Dim strSource As String
Dim strDisposition As String
Dim liValue As Integer
Dim llPct As Long
Dim strMsg As String
Dim strTitle As String
Dim strResponse As String
Dim strReportTemplate As String
DoCmd.SetWarnings False
strCellRefVal = ""
strCellRefPct = ""
strReportTemplate = CurrentProject.Path & "\Source_and_Disposition_Charts.xlsx"
strFileName = CurrentProject.Path & "\Source and Disposition Report - " & Format(Date, "YYYY-MMM-DD") & ".xlsx"
If FileExists(strFileName) Then
Kill strFileName
End If
FileCopy strReportTemplate, strFileName
Set xlApp = CreateObject("Excel.Application")
Set xlBook = GetObject(strFileName)
Set xlSheet = xlBook.Sheets("Data")
{other code goes here, but even if I comment it all out the same problem occurs}
xlBook.Save
xlBook.Close
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
strMsg = "File " & strFileName & " created"
strTitle = "Process complete"
strResponse = MsgBox(strMsg, vbOKOnly, strTitle)
DoCmd.SetWarnings True
End Sub