Open an excel workbook from My.Resources

Hi!

I have an Excel workbook in My.Resources. I want to open it when I use a button. I don't know how to do it Do you have any idea

I can do it by opening the file from its adress (see bellow). I want to do the same job with the excel file from the Resources.

Thanks for your help....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

xlsApp = New Excel.Application

With xlsApp

.Visible = True

.Workbooks.Open("D:\Documents\Fred.xls")

End With

End Sub




Answer this question

Open an excel workbook from My.Resources

  • rgny

    Thank you for that but I don't understand what you are saying. Don't you think it s possible to open directly the excel file from VB (I use the 2005 express edition)

    The file is known as an excel file when I save it in the resources. That's why I thougth it was possible to open it directly as an excel workbook.

    Please give more infos on the binary method you are speaking about. What s a binary reader I don't want to open the file from the disk but from the resources.

    Thanks



  • Ross Miltenberg

    One way to go about it:...Use a binary reader to read the file from resources and save to temp file on disk and then open temp file

  • Kuik

    Well I'm not to sure if you can open an excel file directly from memory...that why i suggested using the biinary writer:

    Private Sub TestResource()

    Dim TempFileName As String = "MyXlsFile.xls"

    TempFileName = Application.StartupPath & "\" & TempFileName

    Dim fs As New FileStream(TempFileName, FileMode.Create, FileAccess.Write)

    Dim fsR As New BinaryWriter(fs)

    fsR.Write(My.Resources.MyXlResource, 0, My.Resources.MyXlResource.Length)

    fsR.Close()

    fs.Close()

    xlsApp = New Excel.Application

    With xlsApp

    .Visible = True

    .Workbooks.Open(TempFileName)

    End With

    End Sub



  • Swatanya

    Thanks a lot Dman1!

    It looks to work perfectly



  • Open an excel workbook from My.Resources