Error while using a string in a range function

vbanovice123

Board Regular
Joined
Apr 15, 2011
Messages
91
Hi,

part of the code is pasted below. I am trying to reference a slide by it's name instead of number while copy and paste into power point rom excel for a data table range. The functionality works when power point slide is referenced by slide number. But when referenced by name, I get an error.

I stepped through the code by setting breakpoints. I see a value of "HFI" for the slide in the copy_range function.
I declared the variable as a string as below: How can I resolve the error?

Dim slidename As String



I get the below:

Run Time error 13. Type mismatch.

Public Function copy_range(sheet, rngname, slide, arheight, arwidth, artop, arleft, vscale)
Sheets(sheet).Select
'Cells(rowStart, columnStart).Resize(row_count, columnCount).Select
Range(rngname).Select
' Make sure a range is selected
If Not TypeName(Selection) = "Range" Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
'PPApp.ActiveWindow.View.GotoSlide (slide)
'PPApp.ActiveWindow.View.GotoSlide (slide)
PPApp.ActiveWindow.View.GotoSlide (slide)
' Reference active slide
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)



Sub Copy2PowerPoint2()
Application.ScreenUpdating = False
'Dim slidenum As Integer
Dim slidename As String
Dim PPTM As PowerPoint.Application
Set PPTM = New PowerPoint.Application
PPTM.Visible = True
PPTM.Presentations.Open Filename:="F:\Focus\Test\OnePagersTemplates_CopyPasteProject\OnePagers_Templates\OriginationsMonitorPackage.pptm"

'slidenum = 11
'HFI
'copy_range(sheet, rngname, slide, aheight, awidth, atop, aleft, vscale)
'copy_range "HFI", "HFIYearQtr", slidenum, arheight, arwidth, artop, arleft, 1
slidename = "HFI"
'HFI
'copy_range(sheet, rngname, slide, aheight, awidth, atop, aleft, vscale)
copy_range "HFI", "HFIYearQtr", slidename, arheight, arwidth, artop, arleft, 1
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
The error is happening at the below line:

ActiveWindow.View.GotoSlide

Is there another syntax to reference a slide that has a string variable defined in an excel vba macro?
 
Upvote 0
I tried the below in both the function call as well as the within the function. Still get a run time error


Set PPSlide = PPPres.Slides("HFI").Layout = ppLayoutTitle
 
Upvote 0
It does not like the below statements

PPApp.ActiveWindow.View.GotoSlide (slidename)
' Reference active slide
'Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Set PPSlide = PPPres.Slides("HFI").Layout = ppLayoutTitle
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top