我的宏运行并从访问表列表中选择报告的名称。但有时我会在名字出现时得到错误" "周围。例如报告" WIP" (S8789080)_07_20_15.xlsx
我会因为" WIP"而得到错误。如何添加其他代码以删除" "来自WIP这个词?附上我的完整代码。
Option Compare Database
Public Function CreatePMReports()
'Turn Warnings Off
DoCmd.SetWarnings False
'Create List of Master Project ID's - all of them
DoCmd.OpenQuery ("qmaktbltMasterProjectID")
'This is for only creating certain PM reports
'DoCmd.OpenQuery ("qmaktbltMasterProjectID_oneoff")
'Create Reports
PMReports
MsgBox ("Weekly PM Reports Complete")
'Turn Warnings On
DoCmd.SetWarnings True
End Function
Public Sub PMReports()
' Set Variables
'Turn Warnings Off
DoCmd.SetWarnings False
'Access
Dim db As Database
Dim rst As Recordset
Dim ssql As String
Dim ssql2 As String
Dim sVariable1 As String
Dim rptpath As String
Dim rptName As String
Dim tmpRptData As String
'Excel
Dim xlApp As Excel.Application
Dim xlWkbk As Excel.Workbook
Dim xlWkbk2 As Excel.Workbook
Dim xlwkbk3 As Excel.Workbook
Dim xlSht As Excel.Worksheet
'Get List of Master Prject ID's
Set db = CurrentDb
Dim DataDate As Date
ssq1 = "SELECT * FROM Calendar"
Set rst = db.OpenRecordset("SELECT *FROM calendar")
DataDate = rst.Fields("reporting date")
ssql = "SELECT * FROM tbltMasterProjectID"
Set rst = db.OpenRecordset("SELECT * FROM tbltMasterProjectID")
rst.MoveFirst
'----------------------------------------------------------------------------------------------
'Loop through whatever records are actually in the master project table, could be one - all per qmaktblMasterProjectID or it's oneoff equivalent
Do While rst.EOF <> True
sVariable2 = rst.Fields("Key")
sVariable1 = rst.Fields("Master Project ID")
'Set Report Path/Name
rptpath = ("G:\TRANS\PPM\9. Enterprise Portfolio & Queue\Clarity Extract\DB and Dashboards\Combined Database\RM DBs\PM\" & sVariable2 & "_" & Format(DataDate, "mm-dd-yy") & ".xlsm")
rptName = ("" & sVariable1 & "_" & Format(DataDate, "mm-dd-yy") & ".xlsm")
'Set Temp Rpt Data Path
tmpRptData = ("C:\DATA\BRM\_Templates\Tmp_PMReportData.xlsx")
'----------------------------------------------------------------------------------------------
'Create Workbook for Master Project
'Set the application
Set xlApp = New Excel.Application
'Make the Application Visible
xlApp.Visible = False
'Set the workbook and the filepath 'Change "C:\Book1.xls " to your own filepath and Workbook name
Set xlWkbk = xlApp.Workbooks.Open("C:\DATA\BRM\_Templates\Template - PM.xlsm ")
'Set the worksheet that you want the workbook to open on
xlApp.Sheets("Data").Select
'Create Workbook Name for PM report
xlWkbk.SaveAs (rptpath)
'Create Workbook Name for PM report
xlWkbk.Close (rptpath)
'----------------------------------------------------------------------------------------------
'Export Project Data
' Update Current Master Project ID
db.Execute ("UPDATE tbltCurrentMasterProjectID SET CurrentMasterProjectID = '" & sVariable1 & "'")
' Export Current Master Project PM View
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "A-Weekly - PMView", tmpRptData
'Export PM View All Resource Data
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "A-Weekly - PMView-rsc", tmpRptData
'----------------------------------------------------------------------------------------------
' Copy Data to Correct Tabs
'Open Workbook
xlApp.DisplayAlerts = False
Set xlWkbk2 = xlApp.Workbooks.Open(rptpath)
Set xlwkbk3 = xlApp.Workbooks.Open(tmpRptData)
'Copy PMView
xlwkbk3.Sheets("A_Weekly___PMView").Select
xlwkbk3.ActiveSheet.Cells.Select
xlwkbk3.ActiveSheet.Cells.Copy
xlWkbk2.Activate
xlWkbk2.Sheets("Data").Select
xlWkbk2.ActiveSheet.Cells.Select
xlWkbk2.ActiveSheet.Paste
xlWkbk2.ActiveSheet.Visible = False
' Copy PM View All Resource Data
xlwkbk3.Activate
xlwkbk3.Sheets("A_Weekly___PMView_rsc").Select
xlwkbk3.ActiveSheet.Cells.Select
xlwkbk3.ActiveSheet.Cells.Copy
xlWkbk2.Activate
xlWkbk2.Sheets("ProjData").Select
xlWkbk2.ActiveSheet.Cells.Select
xlWkbk2.ActiveSheet.Paste
xlWkbk2.RefreshAll
xlWkbk2.RefreshAll
xlWkbk2.RefreshAll
xlWkbk2.ActiveSheet.Visible = False
'Delete TmpPMView Data
xlwkbk3.Activate
xlwkbk3.Sheets("A_Weekly___PMView_rsc").Select
xlwkbk3.Sheets("A_Weekly___PMView").Select
xlwkbk3.ActiveSheet.Delete
xlwkbk3.Sheets("A_Weekly___PMView_rsc").Select
xlwkbk3.ActiveSheet.Delete
'Close Workbooks
xlWkbk2.Save
xlWkbk2.Close (rptpath)
xlwkbk3.Save
xlwkbk3.Close (tmpRptData)
xlApp.Quit
'Turn everything off otherwise yo will have problems with your spreadsheet
Set xlApp = Nothing
Set xlWkbk = Nothing
Set xlSht = Nothing
'----------------------------------------------------------------------------------------------
rst.MoveNext
Loop
rst.Close
DoCmd.SetWarnings True
End Sub
Private Sub test()
DoCmd.SetWarnings True
End Sub
答案 0 :(得分:2)
使用替换功能。
Dim str as string
str = Replace(str, """", "")
答案 1 :(得分:0)
rptName = Replace(rptName, Chr(34), "")