2017-12-16 13 views
0

액세스 권한이없는 Excel 통합 문서를 생성하고 서식을 지정하려고합니다. 파일을 쉽게 만들 수는 있지만 포맷에 어려움이 있습니다.Access VBA에서 사용하는 Excel 응용 프로그램 속성

파일 생성

Dim xl As Object 
'This deals with Excel already being open or not 
On Error Resume Next 
Set xl = GetObject(, "Excel.Application") 
On Error GoTo 0 
If xl Is Nothing Then 
    Set xl = CreateObject("Excel.Application") 
End If 

Set XlBook = GetObject(xlsxPath) 
'filename is the string with the link to the file ("C:/....blahblah.xls") 

'Make sure excel is visible on the screen 
xl.Visible = True 
XlBook.Windows(1).Visible = True 
'xl.ActiveWindow.Zoom = 75 

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

'Format 
With xlsheet1 
    xlsheet1.Rows("1:1").Select 

여기 내 오류가 문자열

strCurrentDBName = CurrentDb.Name 
For i = Len(strCurrentDBName) To 1 Step -1 
    If Mid(strCurrentDBName, i, 1) = "\" Then 
     strPath = Left(strCurrentDBName, i) 
     Exit For 
    End If 
Next 
xlsxPath = strPath & "Report.xlsx" 

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Report", xlsxPath, True 

MsgBox ("Report generated. " & xlsxPath) 

형식으로 희미한 strCurrentDBName (런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류)

xlsheet1.Range(xl.Selection, xl.Selection.End(xlDown)).Select 
    xlsheet1.Selection.EntireRow.AutoFit 

End With 

답변

1

xlDown enum 값을 사용 중입니다. req Microsoft Excel Object Library에 대한 참조입니다. 후기 바인딩을 사용하고 있으므로이 참조는 설정되지 않은 것 같습니다. , -4121을 xlDown의 값을 사용하여 주위

일 :이 오류는 모듈의 상단에 Option Explicit을 두었다면 자리에 더 쉽게 노출 한 것

xlsheet1.Range(xl.Selection, xl.Selection.End(-4121)).Select 

참고.