Question

Setup Environment:

I'm developing an Excel 2010 Application Level Add-in using vb.net.

My goal:

  1. Temporarily save a project resource (i.e. an excel worksheet) to a user's computer
  2. Use vb.net to programmatically query the spreadsheet
  3. After finished, delete the file


This code works to temporarily save and then delete a .png file:

        'Create temporary file path using the commonapplicationdata folder
        Dim picturepath As StringBuilder

        picturepath = New StringBuilder(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))

        picturepath.Append("\chartGridlines.png")

        'Save resources into temp location in HD
        My.Resources.grayGrid.Save(picturepath.ToString, System.Drawing.Imaging.ImageFormat.Png)

        'Add picture to the worksheet
        With Globals.ThisAddIn.Application.Selection.ShapeRange.Fill
            .UserPicture(picturepath.ToString())
        End With

        'Clean up and delete the png from commonapplicationdata folder
        System.IO.File.Delete(picturepath.ToString())


How to do the same thing for .xlsm file?

Visual Studio 2010

Would someone provide a pointer on how I could go about doing this? I'd really appreciate it.

Was it helpful?

Solution

Just do like this:

Imports System.IO

...

File.WriteAllBytes("C:\Path\to\NameList.xlsm", My.Resources.NameList)

The difference is because the image is stored as a Bitmap object, but the Excel file is stored as a byte array.

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top