Joã*_*rro 2 excel vba access-vba
我是Access和VBA的新手,并尝试开发一个简单的代码:将表导出到xls,打开它,简单操作(格式化),保存和关闭.
但是我在这个过程中收到以下消息框: "A file named RESUME.XLW" already exists in this location. Do you want to replace it?"
选择"是"将生成xls文件.但是当我尝试打开它时,Excel以只读模式运行,我不明白为什么.
我正在使用以下代码:
Sub FormataExcelPadrao(caminhoExcel As String)
Set arquivoExcel = CreateObject("Excel.Application")
arquivoExcel.Workbooks.Open (caminhoExcel)
With arquivoExcel
For Each pagina In .Worksheets
With pagina
.Columns("A:Z").Autofit
.Cells.Font.Size = "10"
.Cells.Font.Name = "Calibri"
End With
Next pagina
End With
arquivoExcel.Save
arquivoExcel.Close
End Sub
Run Code Online (Sandbox Code Playgroud)
提前致谢!
定义对象然后使用它.看这个例子
Sub FormataExcelPadrao(caminhoExcel As String)
Dim arquivoExcel As Object, wb As Object, pagina As Object
Set arquivoExcel = CreateObject("Excel.Application")
Set wb = arquivoExcel.Workbooks.Open(caminhoExcel)
With wb '<~~ Also this has to be the workbook and not excel app
For Each pagina In .Worksheets
With pagina
.Columns("A:Z").AutoFit
.Cells.Font.Size = "10"
.Cells.Font.Name = "Calibri"
End With
Next pagina
End With
wb.Close SaveChanges:=True
arquivoExcel.Quit
Set wb = Nothing
Set arquivoExcel = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3961 次 |
最近记录: |