首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >VBA导出为jpg

VBA导出为jpg
EN

Stack Overflow用户
提问于 2020-05-10 08:20:29
回答 1查看 101关注 0票数 0

我成功地实现了使用图表作为JPG导出的代码。但是,当我试图更改文件导出路径时,我得到的错误是运行时错误1004:方法"Range object"_Global file 我不明白代码没有读取什么,因为路径是相似的。

如果有人能帮忙,我会很感激的。

jpg导出到*Path = ThisWorkbook.Path *Path = ThisWorkbook.Path & "\“& Range("PDF_Folder").Value

不导出到*Path = ThisWorkbook.Path & "\“& Range("New_Folder").Value

代码语言:javascript
运行
复制
'//Creat a jpg image using charts
 Dim rng As Range
 Dim shtTemp As Worksheet
 Dim chtTemp As Chart
 Application.ScreenUpdating = False
 '// Range
 Set rng = Worksheets("Receipt").Range("B2:E27")
 shReceipt.rows("2:27").EntireRow.AutoFit
 '// Add a temp worksheet. Chart will be placed on this. It will be deleted after
 Set shtTemp = Worksheets.Add
 '// Add chart
 Charts.Add
 '// Move the chart to the new sheet and get a reference to it
 ActiveChart.Location Where:=xlLocationAsObject, Name:=shtTemp.Name
 Set chtTemp = ActiveChart
 '// Copy and paste the range
 rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
 chtTemp.Paste

 With ActiveChart.Parent
.Height = 520 ' resize
.Width = 360 ' resize
 End With


 '// Export

ChDir ActiveWorkbook.Path
Dim Name As String, Path, filename
Name = InvTable.ListColumns("Customer").DataBodyRange(r).Value
Dim Inv As Double
Inv = InvTable.ListColumns("Invoice Number").DataBodyRange(r).Value

filename = "\" & Inv & "_" & Name & ".jpg"
''//This PDF folder is recognised-no error
Path = ThisWorkbook.Path & "\" & Range("PDF_Folder").Value

''//This path is regonised-no error
'Path = ThisWorkbook.Path

''//This New folder creates an error (it does exist in the workbook path
''Path = ThisWorkbook.Path & "\" & Range("New_Folder").Value
chtTemp.Export filename:=Path & filename
EN

回答 1

Stack Overflow用户

发布于 2020-05-10 11:24:30

所以我找到了答案。"Excel_Folder“是单元格(1,1)中的命名范围(1,1) "PDF_Folder”是单元格(1,2)中的命名范围,这些范围的范围是工作簿

我将"New_Folder“定义为一个命名范围,并找到了路径。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61709057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档