0

我有一个 Excel 报告,Access 中有一些值只有 TRUE/FALSE 答案。如何将每个报告的这些值更改为(例如)打开/关闭。

对于这份报告,我有一个查询 (excel_open_projects),它可以获得我需要的所有值。

Path = CurrentProject.Path & "\"
filename = "Open_Projects_" & Format(Now(), "YYYYMMDDHHNNSS") & ".xls"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel2003, "excel_open_projects", Path & filename

我已经有一个代码可以更改第一行中的值:

Public Sub openXL()
'Variables to refer to Excel Objects
Dim MySheetPath As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Dim row_count, i As Integer

' Tell it location of actual Excel file
MySheetPath = Path & filename
MsgBox MySheetPath

'Open Excel and the workbook
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)

'Make sure excel is visible on the screen
Xl.Visible = True
XlBook.Windows(1).Visible = True

'Define the sheet in the Workbook as XlSheet
Set XlSheet = XlBook.Worksheets(1)

'Insert Row and the Value in the excel sheet starting at specified cell
XlSheet.Range("A1") = "Column A"

'Clean up and close worksheet
XlBook.Save
XlBook.Close

Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing

End Sub

提前感谢您的帮助!

4

1 回答 1

0

我已经解决了问题:

For i = 1 To row_count
If XlSheet.Range("Y" & i) = "True" Then
XlSheet.Range("Y" & i) = "Yes"
ElseIf XlSheet.Range("Y" & i) = "False" Then
XlSheet.Range("Y" & i) = "No"
End If
Next
于 2013-09-18T07:58:25.997 回答