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

NinaE_11

New Member
Joined
Aug 18, 2020
Messages
44
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,863
Office Version
  1. 2016
Platform
  1. Windows
I think either one of these method will guide you
 

Forum statistics

Threads
1,147,518
Messages
5,741,637
Members
423,675
Latest member
Dea21

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
Top