Set Range as variable to use in a copy / paste VBA

NinaE_11

Board Regular
Joined
Aug 18, 2020
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hi! e
I would like to update title page on a PowerPoint presentation with the month end date, referencing a range in Excel that will be dynamic with the =TODAY function from another cell. i.e. today's date is 4/26/21, user would be creating a presentation for prior month end, set to "March 2021". I have written the code a couple of different ways; one with the actual month end / year in the code, formatting will adapt to the presentation, which is what I need. However, when I write VBA to find the range, copy, paste special - the formatting gets dropped. Unfortunately, I don't know the specifics of the formatting (color, etc). The presentation continually references this month end date, so it would be ideal to set it as a variable to continually reference, rather than entering formatting directives at every paste (even if I knew them....) Item 4) is where it falls apart. How do I enter a paste command using a variable into PPT?
VBA Code:
Sub OpenPPTTemplate()

'1.Declare Variables
    Dim papp As PowerPoint.Application
    Dim ppt As PowerPoint.Presentation
    Dim psld As PowerPoint.slide
    Dim psh As PowerPoint.Shape
    Dim rng as Range
      
'2. create a new instance of powerpoint and Open Template Presentation
    Set papp = New PowerPoint.Application
    Set ppt = papp.Presentations.Open("C:Path")
   
'3. Set Slide in PPT
    Set psld = ppt.Slides(1)
    Set psh = psld.Shapes("Title")

'4.  Set the range and copy
       set rng = Workbooks("Template_VBA.xlsm").Worksheets("Char").Range("G19")
       rng.copy
        
    psh.TextFrame.TextRange.Paste

Thank you so much!
 
Last edited by a moderator:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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