Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel save as file format issue

Posted on 2007-12-06
7
Medium Priority
?
4,907 Views
Last Modified: 2008-02-01
After converting a .CSV to an Excel file the Excel file is saved as "Tab delimited". I need it saved as type  "Microsoft Office Excel Workbook". I've tried the attached code but get the below error message.

{"Public member 'XlFileFormat' on type 'Application' not found."}

Reference::
http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.excel.xlfileformat(VS.80).aspx

Thoughts?
Dim objWorkbook = objExcel.Workbooks.Open("C:\ExcelFiles\art.txt")
 
objExcel.ActiveWorkbook.SaveAs("C:\test.xls", objExcel.XlFileFormat.xlWorkbookNormal)

Open in new window

0
Comment
Question by:gabulish
[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
  • 3
  • 2
7 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20423390
just use -4143

objExcel.ActiveWorkbook.SaveAs("C:\test.xls", -4143)
0
 

Author Comment

by:gabulish
ID: 20423939
That works but it causes my code to return an error further down in the function:
 '*****Create Application Spreadsheets
        Dim objExcel = CreateObject("Excel.Application")
        Dim objExcel2 = CreateObject("Excel.Application")
 
        '*****Do not prompt to Save Clipboard Information
        objExcel.DisplayAlerts = False
        objExcel2.DisplayAlerts = False
 
        '*****Added to save changes without being prompted by Excel
 
        Const xlSaveChanges = 1
        Const ForReading = 1
        Const ForWriting = 2
 
        '*****Create Variables for Date/Time Constants
 
        Dim strXlDumpFile = "C:\ExcelF\Dump_" & strMonth & strDay & strYear & strHour & strMin & ".xls"
        Dim strXlHeaderFile = "C:\ExcelF\header.xls"
 
        '****************Execute******************************
        '*****Open .TXT File and Delimit
 
        Dim objFSO = CreateObject("Scripting.FileSystemObject")
        Dim objFile = objFSO.OpenTextFile("C:\ExcelF\test.txt", ForReading)
        Dim strContents = objFile.ReadAll
        objFile.Close()
 
        strContents = Replace(strContents, "|", vbTab)
 
        objFile = objFSO.OpenTextFile("C:\ExcelF\test.txt", ForWriting)
        objFile.Write(strContents)
        objFile.Close()
 
        '*****Convert .TXT File to .XLS File
 
        Dim objWorkbook = objExcel.Workbooks.Open("C:\ExcelF\test.txt")
 
        objExcel.ActiveWorkbook.SaveAs(strXlDumpFile, -4143)
        objWorkbook.Close(xlSaveChanges)
        objExcel.Quit()
 
        '*****Open Headerfile and Copy Row
        Dim objWorkbook2 = objExcel2.Workbooks.Open(strXlHeaderFile)
 
        Dim wsA = objWorkbook2.WorkSheets.item("header")
 
        wsA.Activate()
        wsA.Rows.item(1).Select()
        objExcel2.Selection.Copy()
 
        '*****Paste Headerfile into DumpFile
        Dim objExcelX = CreateObject("Excel.Application")
        Dim objWorkbookX = objExcelX.Workbooks.Open("C:\ExcelF\Dump_" & strMonth & strDay & strYear & strHour & strMin & ".xls")
 
****I get this error on the next line
****Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
****
        Dim wsB = objWorkbookX.WorkSheets.item("Dump_" & strMonth & strDay & strYear & strHour & strMin)
 
 
 
        wsB.Rows(1).Insert()
        wsB.Activate()
        wsB.Rows.item(1).Select()
        wsB.paste()
 
        '*****Close Excel File without prompt to Save
 
        objWorkbookX.Close(xlSaveChanges)
        objWorkbook2.Close(xlSaveChanges)
        objExcel.Quit()
 
        Return MsgBox(".CSV to .XLS conversion complete")
 
    End Function

Open in new window

0
 
LVL 25

Expert Comment

by:imitchie
ID: 20423973
I'm sorry - it is not the "cause"!
Verify that the workbook does exist and is saved correctly. Open it up, and check that there is a worksheet named
"Dump_" & strMonth & strDay & strYear & strHour & strMin

(there probably isn't)
Probably best to just to item(1)  // first sheet
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:gabulish
ID: 20428348
What does the -4143 stand for?
0
 
LVL 25

Accepted Solution

by:
imitchie earned 1400 total points
ID: 20431151
It stands for XlFileFormat.xlWorkbookNormal. but within excel, it knows that "XlFileFormat.xlWorkbookNormal" = -4143
Outside of excel, "XlFileFormat.xlWorkbookNormal" may not mean anything to other programs. So, just use the internal number
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20632931
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 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