Consulting

Results 1 to 4 of 4

Thread: xlRepairFile

  1. #1

    xlRepairFile

    I have a certain excel file and when I open it (without using VBA) it gives an error message:

    "Excel found unreadable content in 'EXP_Explanation_DATA_OVERVIEW_SUMMARY32036.xlsm'.
    Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."

    If I click okay it opens without error. I would like to bypass the error and allow vba to open the workbook but am not sure how to use the XlRepairFile on openworkbook function. Here is the line that it is failing at, I'm not sure where to insert the XlRepairFile piece

    On Error Resume Next: Set wb = Workbooks.Open(MyFolder & "\" & MyFile): On Error GoTo 0
    Here is the full sub, the line of code above is marked 'HELP towards the bottom of the sub

    Sub Inputs1(ByVal x As Integer)
    
    
    'This sub is for the excel piece
    
    
    'tells the macro that the macro is the active workbbook so that it can go_
    'back to the active workbook after opening other workbooks
    
    
        Dim w As Workbook
        Set w = ActiveWorkbook
    
    
    'dim all my variables, these are put in by the user on the main macro workbook
    
    
        Dim Variablez As String
        Dim MyFolder As String
        Dim MyFile As String
        Dim wb As Workbook
        Dim FileName As String
        Dim Action As String
        Dim Location As String
        Dim strPathNFile As String
        Dim NewFile As String
        Dim fileformat As String
        
        
        MyFolder = Trim(Cells(x, 3))
        FileName = Trim(Cells(x, 4))
        Action = Trim(Cells(x, 5))
        Variablez = Trim(Cells(1, 6))
        Location = Trim(Cells(x, 7))
        NewFile = Trim(Cells(x, 8))
        fileformat = "xls"
            
        
        
        
        MyFile = Dir(MyFolder & "\" & FileName & "." & fileformat)
           
        
        FilePath = MyFolder & "\" & FileName
        
        MyNewFile = Dir(Location & "\" & NewFile)
        
        NewFilepath = Location & "\" & NewFile
        
        Application.DisplayAlerts = False
            
           
        'This piece opens the file
        
        If WBIsOpen(MyFile) And Action = "Open" Then
        
        'do nothing except tell the user the report is already open
        Cells(x, 6) = "This report is already open"
        
        Else
        
        If MyFile <> "" And FileName <> "" And Action = "Open" Then
           
        Cells(x, 6) = "This report has been opened"
        
        'On Error Resume Next: Workbooks.Open MyFolder & "\" & MyFile: On Error GoTo 0
        On Error Resume Next: Workbooks.Open MyFolder & "\" & MyFile: On Error GoTo 0
        
        
        End If
        
        End If
        
        
        'this piece saves the file to file
        
        If WBIsOpen(MyFile) And Action = "Save" Then
        
        'do nothing except tell the user the report is already open
        Cells(x, 6) = "This report is already open"
        
        Else
        
        If MyFile <> "" And FileName <> "" And Action = "Save" Then
           
        Cells(x, 6) = "This report has been saved to file"
        
        Application.DisplayAlerts = False
        
    'HELP HELP HELP HELP HELP    
    
    On Error Resume Next: Workbooks.Open FileName:=MyFolder & "\" & MyFile: On Error GoTo 0
        
        
        'save the file to your desired location
        
        Application.DisplayAlerts = False
        
        strPathNFile = Location & "\" & MyNewFile
        ActiveWorkbook.SaveAs FileName:= _
        strPathNFile, _
        fileformat:=xlWorkbookNormal, _
        CreateBackup:=False
        ActiveWindow.Close
        Application.DisplayAlerts = True
        
           
        End If
        
        End If
       
          
        
        If WBIsOpen(MyFile) And Action = "Print" Then
        
        Cells(x, 6) = "This report is already open please close it and try again"
      
         
        Else
        
        
        If MyFile <> "" And FileName <> "" And Action = "Print" Then
        
        
        Cells(x, 6) = "This report has been printed and closed"
        
        
        
        On Error Resume Next: Set wb = Workbooks.Open(MyFolder & "\" & MyFile): On Error GoTo 0
        
        
              
        wb.Sheets.PrintOut
        wb.Close True
        
              
        End If
        
        End If
                       
        w.Activate
    
    
    End Sub

    Thanks,

    Des

  2. #2
    VBAX Regular
    Joined
    Nov 2011
    Posts
    33
    Location
    Try to choose the Below steps

    File >> Option >> Truset Center >> Trust Center Setting >> "Message bar" >."Never show information about blocked content"

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    I have a certain excel file and when I open it (without using VBA) it gives an error message:
    Another thing would be to see WHY there's unreadable content

    Start with a blank workbook and copy and paste the macros and data over to make sure that you're not copying corruptions.

    Or rename the .xlsm to .zip and open it as a zip file. I've tracked down problems that way to at least get started.

    Paul

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Set wb = Workbooks.Open(FileName:=MyFolder & "\" & MyFile, corruptload:=xlrepairfile)
    I think is what you want.
    Be as you wish to seem

Posting Permissions

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