storing path as variable

firechinwessel

New Member
Joined
Jul 29, 2011
Messages
7
I am trying to set up a variable so that a user can enter in the path name of a file that hasn't been made yet. The user needs to create a powerpoint through excel using vba, then name that file so that the path name is the same as the path name entered earlier and stored as a variable. Then the getobject function would be used to call that file so that data could be input into the powerpoint from excel. It must be done this waybecause every time a new powerpoint is created, it will have new name and because the user will eve multiple presentations open already. I tried simply using the "active presentation" but the multiple powerpoint caused data to be input into the wrong powerpoint.

So to recap. The usher clicks a button that creates a new powerpoint. That is then saved. Another button is pushed that stores the path as a variable. A final button is pushed that calls that file up so that datacan be transferred from excel to powerpoint.

Any advice is greatly appreciate! Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
if the user is inputting the path (whole path)

dim asd as string

asd = inputbox ("Please enter full path")

'asd should be something like "C:\test.txt"
 
Upvote 0
That is what I had originally tried. It successfully managed to store the path as a variable, but when I tried to use the GetObject function, it wouldn't work. Using the variable you suggested, it looked like this:

Set PPapp = GetObject(asd,"PowerPoint.Application)

When I tried that, it got an error. Is there anything I'm doing wrong or is there another way?
 
Upvote 0
If you are going to store a variable for use later, you can store it to a cell, or Dim it as Public in a module. You will need some more code to verify that asd exists and that it contains a trailing backslash. I would just call a SaveAs dialog though to let the user have a standard Windows method to set a drive:\folder\filename.ext.

Call each of the Subs from your button's code.

In a Module:
Code:
Option Explicit

Dim asd as String

Sub SetASD
   asd = inputbox ("Please enter full path. e.g. "x:\ppt\")
End Sub

'http://vbaexpress.com/forum/showthread.php?t=22463
Sub ExportXlGraphSheet2PP_dr()
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim lShapesThisSlide As Long
    Dim slidecount As Integer
     ' Allow errors for If check
    On Error Resume Next
    Set PPApp = CreateObject("Powerpoint.application")
     ' Reference active presentation, PP not active will throw error
    Set PPPres = PPApp.ActivePresentation
    PPApp.ActiveWindow.ViewType = ppViewSlide
     ' On error, reference new instance of PowerPoint
    If Err.Number <> 0 Then
        Set PPApp = CreateObject("Powerpoint.Application")
        Set PPPres = PPApp.Presentations.Add
        Set PPPres = PPApp.ActivePresentation
         'Add a slide
        PPPres.Slides.Add 1, ppLayoutBlank
    End If
     
     
    With Application
         ' Allow delete
        .DisplayAlerts = False
         'Speed
        .ScreenUpdating = False
    End With
     
    Sheets("Carte (2)").Delete
     
     ' Create a copy of the sheet
    Sheets("Carte").Copy After:=Sheets(1)
     ' Cut the buttons
    With ActiveSheet
        .Shapes("Group 810").Cut
        .Shapes("Group 807").Cut
    End With
     
     ' Select the range
    Range("A1:O36").Select
     
     ' Copy the range as a picture
    Selection.CopyPicture Appearance:=xlScreen, _
    Format:=xlPicture
     
     ' Kill the 'work' sheet
    Sheets("Carte (2)").Delete
     'Reset excel
    With Application
        .DisplayAlerts = True
        .ScreenUpdating = True
    End With
     
     'No errors allowed
    On Error GoTo 0
     ' Activate PowerPoint
    PPApp.Visible = True
    AppActivate PPApp.Name
     
     ' Reference active slide
    slidecount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(slidecount + 1, ppLayoutBlank)
    PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
     
    PPApp.ActiveWindow.ViewType = ppViewSlide
     ' Get count
    lShapesThisSlide = PPApp.ActiveWindow.Selection.SlideRange.Shapes.Count
     ' Paste to slide
    PPApp.ActiveWindow.View.PasteSpecial (ppPasteMetafilePicture)
     ' Pasted object is 1 count higher than before and no need to select it,just refer to it
    PPApp.ActiveWindow.Selection.SlideRange.Shapes(lShapesThisSlide + 1).Name = "Chart"
     
     ' Unselect shapes (PP)
    PPApp.ActiveWindow.Selection.Unselect
    PPApp.ActivePresentation.SaveAs asd & "ken.ppt", ppSaveAsPresentation
    PPApp.Quit
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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