+ Reply to Thread
Results 1 to 13 of 13

Run time error on SaveAs line of code

  1. #1
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Run time error on SaveAs line of code

    Can anyone tell why I am getting a run time error when the last line of this code is run (.SaveAs FileName)?

    Code:

    Sub CreateNewPres()

    Dim FileName As String
    Dim rng1 As Excel.Range
    Dim ppApp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide

    'Sets the first range we want to copy
    Set rng1 = ThisWorkbook.Worksheets("Sheet3").Range("rng_1")

    'Opens Powerpoint
    Set ppApp = New PowerPoint.Application


    ppApp.Visible = True

    ppApp.Activate

    'Adds new presentation and Title slide
    Set ppPres = ppApp.Presentations.Add
    Set ppSlide = ppPres.Slides.Add(1, ppLayoutTitle)

    'Refers to the shapes within the title slide and input what you want
    ppSlide.Shapes(1).TextFrame.TextRange = "End of Pilot Presentation"
    ppSlide.Shapes(2).TextFrame.TextRange = "Client Name"

    'Adds second slide
    Set ppSlide = ppPres.Slides.Add(2, ppLayoutBlank)
    ppSlide.Select

    'Copies and pastes rng_1
    rng1.Copy
    ppSlide.Shapes.Paste

    'Moves the table of data into the top left corner of the slide
    ppSlide.Shapes(1).Left = 234
    ppSlide.Shapes(1).Top = 234


    'Selects the first chart object in the specified worksheet
    ThisWorkbook.Worksheets("Sheet3").ChartObjects(1).Chart.CopyPicture _
    Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

    'Doesn't seem to like this jump in code
    ppSlide.Shapes.Paste
    ppSlide.Shapes(1).IncrementLeft -100
    'can set it to the width of the slide i.e. width = ppPres.PageSetup.SlideWidth

    'Establishes the Filename
    FileName = "Pilot Presentation" & " " _
    & Format(Now, "dd-mmm-yy")

    'Saves the Presentation using the FileName
    With ppSlide.Parent
    .SaveAs FileName

    End With

    End Sub


    Thanks for the help!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run time error on SaveAs line of code

    What's the error message?

    Does the code work if you use ppPres instead of ppSlide.Parent?

    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Re: Run time error on SaveAs line of code

    Run time error:

    Run-time error '-2147483640 (80000008)':
    Automation error

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run time error on SaveAs line of code

    What happens if you make the change I suggested?

  5. #5
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Re: Run time error on SaveAs line of code

    When I make the change that you suggested I get a new run time error:

    Run-time error '438':
    Object doesn't support this property or method

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run time error on SaveAs line of code

    What exactly did you try?

    This is what I was suggesting.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Re: Run time error on SaveAs line of code

    Yes this is what I tried. Now, when this line: (ppSlide.Shapes.Paste) tries to run, excel closes the workbook and then tries to reopen it.

    Any suggestions

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run time error on SaveAs line of code

    Can you upload a sample workbook so I can test the code?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  9. #9
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Re: Run time error on SaveAs line of code

    I have attached the file I am using,
    The code is in sheet3

    Thanks!
    Attached Files Attached Files

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run time error on SaveAs line of code

    When I run the code straight off I do get an error but it's not at the SaveAs line, it's at the Paste here.

    Please Login or Register  to view this content.
    If I skip that section of code and step through the rest of the code it works fine.

  11. #11
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Re: Run time error on SaveAs line of code

    Yes that is also where I am encountering the error. Is there a way around this?

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run time error on SaveAs line of code

    Off the top of my head I think you'll need to add a shape/textbox/something to the slide and then paste into that.

    PS I thought it was the SaveAs that was causing the problem?

  13. #13
    Registered User
    Join Date
    05-26-2015
    Location
    London
    MS-Off Ver
    Microsoft Office for Mac 2011
    Posts
    18

    Re: Run time error on SaveAs line of code

    Ok great thanks, I will try that

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run time error 1004 - why is the last line of this code causing this?
    By SweetSorcery in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 07-14-2014, 06:57 AM
  2. [SOLVED] Excel Border Line style works for the first time I run the code, later it shows some error
    By vidyaduttk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2014, 05:41 AM
  3. [SOLVED] Converting Unformatted string into Time Value (VBA; error on one line of code)
    By aloha31 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2013, 04:41 PM
  4. Why do I get Run-time error 91 on this line of code?
    By ThomasHaller in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-17-2012, 04:48 PM
  5. Run time error when using activeworkbook.saveas
    By CJPHX in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2010, 11:11 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1