2013-07-26 125 views
0

我有一個Excel報表,Access中有值只有TRUE/FALSE答案。如何將每個報告的這些值更改爲(例如)打開/關閉。訪問 - Excel列表導出替換值

對於這個報告,我有一個查詢(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 

感謝您的幫助提前!

回答

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