PDA

View Full Version : VBA Sort in a excel sheet inside my presentation



R1mon
05-08-2010, 07:31 AM
Hello,

I'm want to sort data in which is in an excel sheet in my PowerPoint presentation. I'm using the following VBA code in PowerPoint to do this:


Dim FillSheet As Excel.Worksheet

Set FillSheet = ActivePresentation.Slides(1).Shapes("Object 8").OLEFormat.Object.Application.Workbooks(1).Worksheets(1)

With FillSheet.Sort
.SortFields.Clear
.SetRange Range("A1:B5")
.SortFields.Add Key:=Range("D4"), Order:=xlAscending 'Key:=Range("A1"), Order:=xlDescending
.SortMethod = xlPinYin
.Orientation = xlTopToBottom
.Header = xlGuess
.MatchCase = False
.Apply
End With


The declaration of the worksheet is correct (I can fill the sheet using VBA).
I suppose the sort code is also correct because it works when using it directly in Excel.

when I'm excecute the above code I get the folling error:


Run-time error '1004':

Method 'Range' of object '_Global' failed

it appeare on line:
.SetRange Range("A1:B5")
Can anyone help me with this error?