有沒有辦法使用Excel-VBA代碼來製作圖紙中的圖片對象,以便將其作爲頁腳圖像插入。我試圖通過創建一個圖表對象,並在圖片格式粘貼,然後圖表導出爲圖像文件,並設置圖像的頁腳這樣做。有沒有更好的方法來將圖片對象作爲頁腳圖片插入,如果是的話,我該怎麼做?Excel VBA頁腳圖像
0
A
回答
1
我開始了宏記錄器。我點擊Page Setup
然後Header/Footer
然後Custom Footer
。我點擊了中心部分,然後Format Picture
(太陽在山上的圖像按鈕)。我瀏覽了一張圖片並點擊了Insert
。 「& [圖片]」出現在中心部分。我點擊了OK
兩次。我關掉了微距記錄器。
我打印了頁面,所選圖像出現在底部。
由宏記錄保存重要的代碼是:
ActiveSheet.PageSetup.CenterFooterPicture.Filename = _
"C:\Users\Public\Pictures\Sample Pictures\Desert Landscape.jpg"
替換"C:\Users\Public\Pictures\Sample Pictures\Desert Landscape.jpg"
與您所選擇的文件名。
微距記錄器通常是發現這樣的語句的最簡單的方法。
+0
我想要從excel表格中的圖片對象插入footerimage而不是外部圖片 – roshanK 2012-05-02 07:24:37
0
試試這個:
Dim ws as Worksheet
Set ws = Worksheets("YourWorksheetName")
With ws.PageSetup
.CenterFooterPicture = "&G" 'Specifies that you want an image in your footer
.CenterFooterPicture.Filename = "C:\Pictures\MyFooterImage.jpg" 'specifies the image file you want to use
End With
由宏錄製生成的代碼將讓你的存在方式的一部分,但通常情況下,它並沒有提供全部的或最合適的解決方案。這聽起來像是你試圖將由Excel生成的圖像(如圖表)插入頁腳?如果是這樣的話,我相信你將不得不與圖像相同的對象,然後引用該圖像文件。
1
對於任何人在將來查看此內容,我將分享我的代碼以複製範圍並將其另存爲計算機上的文件,然後將其添加到頁腳。您可以消除您不想要的任何位=)
Dim objPic As Shape
Dim objChart As Chart
Dim strTimeStamp As String
Dim strFileDest As String
20 Sheets(2).Activate
30 Sheets(2).Columns("R:T").AutoFit
40 Sheets(2).Rows("17:21").AutoFit
50 ActiveWindow.DisplayGridlines = False
60 Call Sheets(2).Range("S17", "U21").CopyPicture(xlScreen, xlPicture)
70 ActiveWindow.DisplayGridlines = True
80 Sheets(2).Shapes.AddChart
90 Sheets(2).Activate
100 Sheets(2).Shapes.Item(1).Select
110 Set objChart = ActiveChart
120 ActiveChart.Parent.Name = "FooterChart"
' For some reason, Excel occasionally tries to make an actual chart out of these strings.
' It's just a nonsensical chart that messes the footer up but I'm having trouble duplicating the issue and figuring out what causes it.
' This should always work. Don't use .Clear, it crashes.
130 ActiveChart.ChartArea.ClearContents
140 objChart.Paste
150 Selection.Name = "FooterImage"
160 ActiveSheet.ChartObjects("FooterChart").Activate
170 Sheets(2).Shapes.Item(1).Line.Visible = msoFalse
180 Sheets(2).Shapes.Item(1).Height = Range("S17", "U21").Height
190 Sheets(2).Shapes.Item(1).Width = Range("S17", "U21").Width
200 ActiveChart.Shapes.Range(Array("FooterImage")).Height = Range("S17", "U21").Height
210 ActiveChart.Shapes.Range(Array("FooterImage")).Width = Range("S17", "U21").Width
220 Sheets(2).Shapes.Item(1).Height = Sheets(2).Shapes.Item(1).Height * 1.25
230 Sheets(2).Shapes.Item(1).Width = Sheets(2).Shapes.Item(1).Width * 1.25
240 ActiveChart.Shapes.Range(Array("FooterImage")).Height = ActiveChart.Shapes.Range(Array("FooterImage")).Height * 1.2
250 ActiveChart.Shapes.Range(Array("FooterImage")).Width = ActiveChart.Shapes.Range(Array("FooterImage")).Width * 1.2
260 strTimeStamp = CStr(Format(Now(), "yyyymmddHhNnSs"))
270 strFileDest = "D:\Temp" & strTimeStamp & ".jpg"
280 objChart.Export strFileDest
290 InsertPicture strFileDest
300 If Len(Dir$(strFileDest)) > 0 Then
310 Kill strFileDest
320 End If
330 Sheets(2).Shapes.Item(1).Delete
相關問題
- 1. Excel到PDF轉換與頁腳圖像
- 2. Excel VBA 2013打印圖像
- 3. Excel VBA找到網頁圖像並將其導入excel
- 4. Excel VBA腳本
- 5. Excel VBA組成自己的頁腳
- 6. Excel 2010 VBA腳本
- 7. Java Excel API:將圖像添加到Excel文件的頁腳
- 8. VBA Excel - 頁眉和頁腳動態頁碼(頁數)
- 9. Excel VBA在頁眉和頁腳中打印日期和頁碼
- 10. Excel VBA:從另一個頁面顯示來自URL的圖像
- 11. Excel VBA圖片
- 12. Excel VBA從url獲取圖像
- 13. Excel VBA - 如果條件上的圖像
- 14. 嵌入式圖像從Excel VBA
- 15. 標題中的Excel vba參考圖像
- 16. VBA的Excel - 取消頁眉和頁腳在Word
- 17. Excel VBA - 讓VBA腳本遍歷行
- 18. Excel的VBA腳本清楚
- 19. excel和IE的VBA腳本
- 20. Excel VBA腳本幫助
- 21. 優化Excel VBA腳本
- 22. Excel VBA:將圖像從圖像控件複製到activeX對象
- 23. Excel VBA從圖像名稱列中插入圖像
- 24. 來自資源的圖像作爲excel中的頁腳
- 25. setOnclilcklistener爲頁腳圖像
- 26. Typeahead.js與圖像和頁腳
- 27. 頁腳背景圖像css
- 28. Prestashop 1.7頁腳圖像
- 29. 頁腳覆蓋圖像
- 30. Excel VBA MultiPage - 獲取頁數
@roshanK:好像你忽視了http://stackoverflow.com/questions/9902462/excel-vba-insert-footer-image我的評論: ) – 2012-03-29 14:01:33
@SiddharthRout no..i確實關閉了所有的問題 – roshanK 2012-03-29 14:35:53
是:)我提醒你後:) – 2012-03-29 16:14:34