none
System.ArgumentException: Value does not fall within the expected range. at microsoft office interop Excel_Workbook ExportAsFixedFormat() RRS feed

  • Question

  • hie guys

    i am developing an application using vb.net and when i try to run in on a certain machine running windows 10 home and Office 2010 that is when the error appears when converting excel workbook to pdf

    here is my code

    Dim invsignature As String = ""
            invsignature = resultvalues(0) + "" + resultvalues(2)


            Dim excelApp As New Excel.Application
            excelApp.Visible = False

            xlWorkBook = excelApp.Workbooks.Open("C:\tawanda\tawa.xlsx")         
            xlWorkSheet = xlWorkBook.Worksheets("myExl")
            xlWorkSheet.Cells(38, 2) = Trim(invsignature)
            xlWorkBook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, "C:\tawanda\tawa" + a + ".pdf")
            excelApp.DisplayAlerts = False
            excelApp.Quit()
            Try
                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet)
                xlWorkSheet = Nothing
                xlWorkBook = Nothing
            Catch ex As Exception
                xlWorkSheet = Nothing
                xlWorkBook = Nothing
            Finally
                GC.Collect()
            End Try

            Dim p() As Process
            p = Process.GetProcessesByName("EXCEL")
            If p.Count > 0 Then
                'MsgBox("running")

                ' Process is running
            Else
                ' Process is not running
            End If





            excelApp.Visible = False
            excelApp.DisplayAlerts = False
            excelApp.Quit()
            ' excelApp.

    Friday, August 24, 2018 2:13 PM

Answers

  • Have you tried this on more than one computer and one failed? 

    Did both computers try the same exact Excel file?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Towernter Monday, August 27, 2018 6:35 AM
    Friday, August 24, 2018 4:01 PM
    Moderator

All replies

  • Have you tried this on more than one computer and one failed? 

    Did both computers try the same exact Excel file?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Towernter Monday, August 27, 2018 6:35 AM
    Friday, August 24, 2018 4:01 PM
    Moderator
  • i tried it on more than one computer using the same exact Excel file but only one failed

    Monday, August 27, 2018 6:34 AM