Solved

create temporary excel workbook with 1 sheet

Posted on 2014-04-29
2
1,946 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

839 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