Results 1 to 6 of 6

Thread: PowerPoint VB issue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jun 2023
    Posts
    1
    Location

    PowerPoint VB issue

    Hi all

    I've done a lot of Excel VB but only just starting with VB in PowerPoint. A colleague had the following VB created by Chat GPT (no really!) so no idea if it's just rubbish or if it just needs a minor tweak. When we run the code, it brings up a run time error at the line in bold, below. It creates the title slide and the first content slide but goes no further; unfortunately I have no PPT VB knowledge, so don't know if this should work! TIA

    Sub CreatePrescribingConsiderationsDeck()
        Dim PowerPointApp As Object
        Dim PowerPointPres As Object
        Dim PowerPointSlide As Object
       
        ' Create a new PowerPoint application
        Set PowerPointApp = CreateObject("PowerPoint.Application")
        PowerPointApp.Visible = True
       
        ' Create a new PowerPoint presentation
        Set PowerPointPres = PowerPointApp.Presentations.Add
       
        ' Add a title slide
        Set PowerPointSlide = PowerPointPres.Slides.Add(1, 1)
        PowerPointSlide.Shapes.Title.TextFrame.TextRange.Text = "Prescribing Considerations in Older People"
       
        ' Add content slide - Problems with Polypharmacy
        Set PowerPointSlide = PowerPointPres.Slides.Add(2, 11)
        PowerPointSlide.Shapes.Title.TextFrame.TextRange.Text = "Problems with Polypharmacy"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = "Polypharmacy, the use of multiple medications, can pose significant challenges in older people:"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Increased risk of drug interactions"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Higher likelihood of medication non-adherence"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Increased potential for adverse drug reactions"
       
        ' Add content slide - Cholinergic Burden
        Set PowerPointSlide = PowerPointPres.Slides.Add(3, 11)
        PowerPointSlide.Shapes.Title.TextFrame.TextRange.Text = "Cholinergic Burden"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = "Cholinergic burden refers to the cumulative effect of medications with anticholinergic properties. In older people:"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Anticholinergic medications can contribute to cognitive impairment, falls, and delirium"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Assess the cholinergic burden when prescribing medications"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Consider non-pharmacological alternatives when appropriate"
       
        ' Add content slide - Pain Management
        Set PowerPointSlide = PowerPointPres.Slides.Add(4, 11)
        PowerPointSlide.Shapes.Title.TextFrame.TextRange.Text = "Pain Management"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = "Pain management in older people requires careful consideration:"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Balance the need for effective pain relief with the risk of adverse effects"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Consider individualized approaches based on pain intensity, comorbidities, and functional status"
        PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text = PowerPointSlide.Shapes.Placeholders(2).TextFrame.TextRange.Text & vbCrLf & "- Non-pharmacological interventions, such as physical therapy or heat/cold therapy, should be explored"
       
        ' Save the PowerPoint presentation
        PowerPointPres.SaveAs "H:\PrescribingConsiderations.pptx"
       
        ' Close the PowerPoint application
        PowerPointApp.Quit
       
        ' Release the PowerPoint objects from memory
        Set PowerPointSlide = Nothing
        Set PowerPointPres = Nothing
        Set PowerPointApp = Nothing
       
        MsgBox "PowerPoint deck created successfully!"
    End Sub
    Last edited by Aussiebear; 06-06-2023 at 02:01 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •