Search code examples
excelvb.netexcel-interopimport-from-excel

Programmatically name an Excel workbook from VB.net


How do I name an excel workbook that I created using VB.net Below is my code

appXL = CreateObject("Excel.Application")
wbXL = appXL.Workbooks.Add()

I wish for the line below to produce set the workbook name but it keeps giving me an error.

wbXL.Name = "WorkbookName"

I also tried the code below but it didn't work.

wbXL.Name().Replace(wbXL.Name, "WorkbookName")

Any help will be greatly appreciated


Solution

  • Thanks @Storax for the pointer. I was able to come up with this

    wbXL.SaveAs(Filename:= "WorkBookName")
    

    I will write a code to look into the directory and delete the file anytime the code re-runs so it doesn't ask to overwrite because it already exits.

    Thank you guys a lot