I created an Excel file based on 3 queries and a report. However, the alignment of the fields in the Excel file is not correct. Fields shifted over 1 cell position when the report was migrated to an Excel spreadsheet.
Based on the following procedures, is there a way to change the cells in the Excel file as follows:
Fortuantely, the Excel output file will always be in the same cell positions each time the function runs to geneate the Excel spreadsheet.
Ideally I would like to perform the following cell manipulations:
a) Set cells A1, C1 and D1 to blanks.
b) move value of cell G9 TO F9 (OVERLAY F9)
I9 TO H9 (OVERLAY H9)
G17 TO F17 (OVERLAY F17)
I17 TO H17 (OVERLAY H17)
G25 TO F25 (OVERLAY F25)
I25 TO H25
G33 TO F33
I33 TO H33
G41 TO F41
I41 TO H41
G42 TO F42
I42 TO H42
Overlay the contents H25, F33, H33, F41, H41, F42 AND H42.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Function StartDoc(ByVal FileName As String, Optional CommandLine As String = "") As Long
StartDoc = ShellExecute(0&, "Open", FileName, CommandLine, vbNullString, 1)
End Function
Private Function isFileExist(filePath As String) As Boolean
isFileExist = (filePath <> "" And dir$(filePath) <> "")
End Function
Private Sub QuerySummToExcel()
Dim rstQuery As ADODB.Recordset, ExportedFile As String
ExportedFile = "C:\MyFileName.xls"
Set rstQuery = CurrentProject.Connection.Execute("qryCustValMthRange", , adCmdStoredProc)
Set rstQuery = CurrentProject.Connection.Execute("qryCustValDollRange", , adCmdStoredProc)
Set rstQuery = CurrentProject.Connection.Execute("qryCMR", , adCmdStoredProc)
DoCmd.OutputTo acOutputReport, "RptSummaryReport", acFormatXLS, ExportedFile
if isFileExist(ExportedFile) then StartDoc ExportedFile
End Sub
Based on the following procedures, is there a way to change the cells in the Excel file as follows:
Fortuantely, the Excel output file will always be in the same cell positions each time the function runs to geneate the Excel spreadsheet.
Ideally I would like to perform the following cell manipulations:
a) Set cells A1, C1 and D1 to blanks.
b) move value of cell G9 TO F9 (OVERLAY F9)
I9 TO H9 (OVERLAY H9)
G17 TO F17 (OVERLAY F17)
I17 TO H17 (OVERLAY H17)
G25 TO F25 (OVERLAY F25)
I25 TO H25
G33 TO F33
I33 TO H33
G41 TO F41
I41 TO H41
G42 TO F42
I42 TO H42
Overlay the contents H25, F33, H33, F41, H41, F42 AND H42.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Function StartDoc(ByVal FileName As String, Optional CommandLine As String = "") As Long
StartDoc = ShellExecute(0&, "Open", FileName, CommandLine, vbNullString, 1)
End Function
Private Function isFileExist(filePath As String) As Boolean
isFileExist = (filePath <> "" And dir$(filePath) <> "")
End Function
Private Sub QuerySummToExcel()
Dim rstQuery As ADODB.Recordset, ExportedFile As String
ExportedFile = "C:\MyFileName.xls"
Set rstQuery = CurrentProject.Connection.Execute("qryCustValMthRange", , adCmdStoredProc)
Set rstQuery = CurrentProject.Connection.Execute("qryCustValDollRange", , adCmdStoredProc)
Set rstQuery = CurrentProject.Connection.Execute("qryCMR", , adCmdStoredProc)
DoCmd.OutputTo acOutputReport, "RptSummaryReport", acFormatXLS, ExportedFile
if isFileExist(ExportedFile) then StartDoc ExportedFile
End Sub