dev-resources.site
for different kinds of informations.
Word VBA 刪除所有圖形
Published at
9/18/2024
Categories
vba
word
Author
codemee
Author
7 person written this
codemee
open
因為工作的需要, 所以問了 Claude 如何使用 VBA 刪除文件內所有的圖形, 於是得到了這樣的解法:
Sub 移除繪圖物件()
Dim shp As shape
For Each shp In ActiveDocument.Shapes
shp.Delete
Next shp
MsgBox "所有圖形物件已被刪除。", vbInformation
End Sub
實際運作的確可以刪除所有的圖形, 只是有個想問題, 我得重複執行好幾次才能刪掉所有的圖形, 再次詢問 Clause, 它以為我是沒有刪除 InlineShapes 集合的圖形。改問 Microsoft Copilot 後, 提醒了我, 因為這個集合是動態的, 上述解法會導致集合內的項目數量變化, 原本要取出的下一個項目的索引值變了, 例如本來在索引位置 2 的項目, 因為索引位置 1 的項目被刪除了, 現在變成索引 1, 如果還是取索引項目 2 的項目, 就會是最開始索引項目 3 的項目, 遺漏了本來要取出的項目:
index 1 2 3
|20| 7|45|
-- -- --
刪除 20 後:
index 1 2 3
| 7|45|
-- -- --
應該要直接以倒序的方法使用索引取值的方式刪除才不會有問題:
Sub 移除繪圖物件()
For i = ActiveDocument.Shapes.Count To 1 Step -1
ActiveDocument.Shapes(i).Delete
Next i
MsgBox "所有圖形物件已被刪除。", vbInformation
End Sub
word Article's
30 articles in total
Using LLM to translate in Microsoft Word locally
read article
Using Mistral NeMo to summarize 10+ pages in Microsoft Word locally
read article
Empowering Your Team with Phi-4 in Microsoft Word within Your Intranet
read article
Using OpenLLM in Microsoft Word locally
read article
Using Xinference in Microsoft Word locally
read article
Using Ollama in Microsoft Word locally
read article
Using LocalAI in Microsoft Word locally
read article
Using llama.cpp in Microsoft Word locally
read article
Using LM Studio in Microsoft Word locally
read article
Using AnythingLLM in Microsoft Word locally
read article
Using LiteLLM in Microsoft Word, locally or remotely
read article
Using Phi-4 in Microsoft Word locally
read article
mala direta usando o VBA, Excel e Word tudo juntos
read article
UZI -> Find and replace text in multiple files(docx,xlsx,pptx..)
read article
From XML to Word: simplifying conversion with FileConversionLibrary
read article
How to Disable Removal of Formatting When Pasting Text in Microsoft Word for Mac
read article
Word VBA 刪除所有圖形
currently reading
4 Simple Ways to Split Word Documents Using C#
read article
converttools
read article
Quest Words: Word Connect
read article
How to Easily Import Data from Word Documents into Your App: A Complete Guide
read article
Creating Word Search: Word Puzzle Game – A Creative Endeavor by the Maker of WiseApp Brain Game
read article
Unlocking Minds with Letters: How ‘Fresh Words: Word Game’ Became a Sensation in Brain Training
read article
What’s New in 2023 Volume 4: File Format Libraries
read article
5 C# Word Libraries Most .NET Developers Use in Project
read article
How to Open A Word Document in C#
read article
Comment ajouter un en-tête et un pied de page à Word avec Python
read article
BİLGİSAYAR KURSU
read article
Comment trouver et surligner du texte dans Word avec Python
read article
Comment définir la couleur de fond ou l'image de fond pour Word avec Python
read article
Featured ones: