| View previous topic :: View next topic |
| Author |
Message |
rebelxt OOo Enthusiast


Joined: 10 Dec 2006 Posts: 114 Location: StLouis
|
Posted: Sun Feb 18, 2007 2:30 pm Post subject: How to locate and delete picture from spreadsheet |
|
|
The following routine will locate and delete all the pictures from one sheet in an Excel workbook. How can I accomplish the same thing in Calc?
| Code: | Public Function DeletePictures(wSheet As String)
'Purpose: Delete all pictures associated with the specified worksheet.
'Arguments:
' wSheet: Name of worksheet containing pictures
Dim n, c
n = Worksheets(wSheet).Shapes.Count
Do Until n = 0
c = Worksheets(wSheet).Shapes(n).Name
If Left(c, 8) = "Picture " Then
Worksheets(wSheet).Shapes(n).Delete
End If
n = n - 1
Loop
End Function
|
Actually, all I really need to know is what statement(s) are required to locate the pictures, and the statement that will delete them. |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Mon Feb 19, 2007 2:57 am Post subject: Re: How to locate and delete picture from spreadsheet |
|
|
| rebelxt wrote: | The following routine will locate and delete all the pictures from one sheet in an Excel workbook. How can I accomplish the same thing in Calc?
(...)
Actually, all I really need to know is what statement(s) are required to locate the pictures, and the statement that will delete them. |
Your function is in fact a Sub. Equivalent for Calc | Code: | Sub DeletePictures(sheetName as string)
dim myCalc as object, mySheet as object, myPage as object
dim obj as object, x as long
myCalc = thisComponent
mySheet = myCalc.Sheets.getByName(sheetName)
myPage = mySheet.DrawPage
for x = myPage.Count -1 to 0 step -1
obj = myPage(x)
if obj.supportsService("com.sun.star.drawing.GraphicObjectShape") then
myPage.remove(obj)
' Issue 74651 : document does not set itself as modified
myCalc.setModified(True) ' work-around for the bug
end if
next
End Sub |
I found Issue 74651 when creating this macro. |
|
| Back to top |
|
 |
rebelxt OOo Enthusiast


Joined: 10 Dec 2006 Posts: 114 Location: StLouis
|
Posted: Mon Feb 19, 2007 12:36 pm Post subject: |
|
|
Thanks, B, your subroutine worked just fine. I didn't have to change a thing. I wasn't expecting anyone to do the coding and debugging for me, but I'm sure that "issue 74651" thing would have caused me a lot of grief.
Thanks again,
rebelxt |
|
| Back to top |
|
 |
|