[Writer] How to remove all pictures from a document?
Hey, as title said, how would I go about removing all the pictures from a document in LibreOffice Writer?
Thank you.
First time here? Check out the FAQ!
Hey, as title said, how would I go about removing all the pictures from a document in LibreOffice Writer?
Thank you.
delete On all pages (works in 2020)
Sub DeleteAllPics()
Dim oDoc As Object
Dim oDrawPage As Object
Dim oShape As Object
Dim iShape As Integer
Dim iSheet As Integer
oDoc = ThisComponent
For iSheet = 0 To oDoc.getSheets().getCount() - 1
oDrawPage = oDoc.getSheets().getByIndex(iSheet).getDrawPage()
For iShape = oDrawPage.getCount() - 1 To 0 Step -1
oShape = oDrawPage.getByIndex(i)
oDrawPage.remove(oShape)
Next iShape
Next iSheet
End Sub
getByIndex(i)
is likely wrong - needs to be getByIndex(iShape)
And use Long
, not Integer
.
This answer is drawn from "How to remove all the images in a document in LibreOffice Writer?" on AskUbuntu StackExchange. Thanks @chaskes!
The easiest way to do this is via a macro. The following steps will make it availabe as a Toolbar menu item.
Tools > Macros > Organise macros > LibreOffice Basic...
(a new window opens).Now we need to get the LO Basic code to paste in below that "End Sub" line. Copy this code block:
Sub RemoveImages
Dim oDoc as Object
oDoc = ThisComponent
Dim oGraphics as Object
oGraphics = oDoc.getGraphicObjects()
Dim oImg as Object
For Each oImg in oGraphics
oDoc.getText().removeTextContent(oImg)
Next
End Sub
Return to the LibreOffice Macro editor, position your cursor under the "End Sub" line, then hit CTRL-V
to paste it in. Press CTRL-S
to save it.
You could just run the macro from Tools > Macros > Organise macros > LibreOffice Basic...
, click on RemoveImages
, then click "Run" (the top button on the right). If you're doing this infrequently, that's probably good enough. If you think you might be using this more often, then it can be assigned to the menus by following these steps:
Customise > Menus
, then choose the menu you want to add your macro to from the Menu drop-down. I used "Edit".Add...
button on the right of the dialog, and scroll to the bottom of the "Category" listing until you see > LibreOffice Macros
.My Macros > Standard > Module 1
. You should now see "RemoveImages" listed in the right-hand "Commands" box. Click on it to select it.Add
button (which will add the macro to your chosen menu), then Close
, to close the "Add Commands" dialog.⇧
and ⇩
buttons to locate the "RemoveImages" macro precisely where you want it in the menu. When finished, click OK
.Removing all the images in your Writer document is now only one click away.
thanks this works perfectly. i would upvote but i dont have enough rep
I tried this (Dec 2017) and got error "BASIC runtime error. Property or method not found: getGraphicObjects" on Windows 7 LO Version: 5.4.2.2 (x64) Any suggestions on how to fix this?
Asked: 2015-09-06 19:24:28 +0100
Seen: 5,175 times
Last updated: Feb 14 '20
Image copy and Paste issue [closed]
How do you add bullets to an already number-bulleted group of statements? [closed]
Can I use Microsoft Publisher files with LibreOffice? [closed]
Alternating table column numbering, Col1 Numbers, Col2 Letters? [closed]
Are there any plans to improve image handling? [closed]
LibreOffice 3.5 Writer crashes when making PDF [closed]
How can I center the document in a Writer window? [closed]
How to change datasource in form letter / mail merge imported from MS-Word [closed]