locked
Error Handling, Excel RRS feed

  • Question

  • The following code goes to SharePoint, downloads a worksheet from the SharePoint, copies the worksheet to an existing workbook, then renames the downloaded worksheet.

    -----------------------------------------------------------
     
    Public Sub ImportFileName()
     
        ' Define Workbook and Worksheet Variables
        Dim wkbMyWorkbook As Workbook
        Dim wkbWebWorkbook As Workbook
        Dim wksWebWorkSheet As Worksheet
        
        Set wkbMyWorkbook = ActiveWorkbook
        
        ' Open The Web Workbook
        Workbooks.Open (webaddress_filename_ext)
        
        ' Set the Web Workbook and Worksheet Variables
        Set wkbWebWorkbook = ActiveWorkbook
        Set wksWebWorkSheet = ActiveSheet
        
        ' Copy The Web Worksheet, delete if already exists in this Workbook the Insert and ename
        wksWebWorkSheet.Copy after:=wkbMyWorkbook.Sheets(Sheets.Count)
        wkbMyWorkbook.Activate
        Call DeleteFileName
        wkbMyWorkbook.Sheets(ActiveSheet.Name).Name = "NewWorksheetsName"
        
        ' Close the Web Workbook
        wkbMyWorkbook.Activate
        wkbWebWorkbook.Close False
     
    End Sub
    -----------------------------------------------------------
     
    I use "Call ImportFileName" to run it and I have several copies that are repeated for other SharePoints.
     
    I wish to add some Error Handling so that the code does not crash when a file is missing on one of the SharePoints.

    Thank you for any assistance you are able to provide.

    Rich

    Friday, April 24, 2015 1:14 PM

Answers

All replies

  • Hi,

    I have an "Error Handling" example in combinations with saving a file in Excel. Maybe it helps, see below link.

    https://gallery.technet.microsoft.com/VBA-Error-Handling-17bdb38a

    Regards,

    Reshma


    Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered

    • Marked as answer by RichMWilliams Saturday, April 25, 2015 1:03 PM
    • Unmarked as answer by RichMWilliams Sunday, April 26, 2015 4:55 AM
    • Marked as answer by RichMWilliams Sunday, April 26, 2015 4:55 AM
    Friday, April 24, 2015 5:46 PM
  • Hi Reshma,

    Thank you!  Your "Error Handling" example did the trick.  Thanks for your excellent help!

    Best regards,

    Rich

    Saturday, April 25, 2015 1:05 PM
  • Hi Rich,

    Happy to hear that my "Error Handling" example in the gallery did the trick.

    If it is possible, maybe you would like to rate the example? I would really appreciate it.

    Thank you,

    Reshma


    Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered

    Saturday, April 25, 2015 10:57 PM
  • Hi Reshma,

    I have previously clicked "Mark as answer" for your response.

    In you most recent response, you have noted "Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark as Answer when question is answered".  How do I do this?  I have searched the site for an answer to this, but I cannot find one.

    Thanks in advance,

    Rich

    Sunday, April 26, 2015 5:04 AM
  • Hi Rich,

    Thank you for your vote. I wanted to ask if you could rank the stars in the Gallery.

    When you go to the link https://gallery.technet.microsoft.com/VBA-Error-Handling-17bdb38a you wil see stars, if you like the gallery thread then please rank in there.

    Thank you for trying.

    Reshma


    Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered

    Sunday, April 26, 2015 11:57 AM