访问 - Excel列表导出替换值

时间:2013-07-26 07:34:22

标签: excel vba excel-vba export report

我有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

提前感谢您的帮助!

1 个答案:

答案 0 :(得分: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