Solved

create temporary excel workbook with 1 sheet

Posted on 2014-04-29
2
2,082 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

705 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