Solved

create temporary excel workbook with 1 sheet

Posted on 2014-04-29
2
1,793 Views
Last Modified: 2014-04-30
I have a spreadsheet that opens a word document in vba and then merges the data on sheet4 to the word document.  Works great.  Then I move it to a SharePoint server and it keeps coming back and saying it cant find the file, with the data, which is the file that is open already open.  Again runs fine locally.  So I'm thinking because its actually in a database and not in a file is the reason I have the problem, so I'm thinking create a local temporary workbook with the data sheet in it and merge that file instead.  So the question becomes how to create the workbook, then add and name the sheet, then run my program to save data to the sheet ( this I have) and then save to the users documents folder, so that I can use that file to merge instead.

thanks for the help
0
Comment
Question by:mgmhicks
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 40031209
It's straightforward to create a workbook with one worksheet.

This code, run in Excel VBA, will do it.
Dim wbNew As Workbook

   Set wbNew = Workbooks.Add(xlWBATWorksheet)

   wbNew.Sheets(1) = "NewSheetName"

    ' run your code with newly created workbook

Open in new window

If you want to name the new workbook you'll need to save it.

This will save the workbook create with the previous code.
wbNew.SaveAs "C:\Test\MyFolder\NewWorksheetName.xlsx", Format:=xlOpenXMLWorkbook

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now