Link to home
Start Free TrialLog in
Avatar of visualbasic
visualbasicFlag for Ireland

asked on

Modify and Saving an excel file as ? in within VB

I want to open an excel file ,modify one cell and then save as
any of the following types.

Microsoft Excel 97 && 5.0/95 Workbook
Microsoft Excel 5.0/95 Workbook
Microsoft Excel 4.0 Workbook
Microsoft Excel 3.0 Worksheet
Microsoft Excel Workbook
WK4(1-2-3)
WK3(1-2-3)
WK1(1-2-3)
WKs(1-2-3)
Text (Tab Delimited)

How can I do this?
Avatar of thenrich
thenrich

The way your question is asked it seems you can do all of what you are asking right from excel without VB. At what point does VB do anything. We need some more specifics.
Try yourself

Open new excel and click on tools, macro and then record new macro.

Save your excel by choosing your save as.

stop the macro and press Alt-
F11, you should see the code on modules folder-module1

for example

ActiveWorkbook.SaveAs Filename:="C:\temp\Book1.xls" _
        , FileFormat:=xlExcel2, Password:="", CreateBackup:=False
Avatar of visualbasic

ASKER

I want to create a stock list from within vb.the user selects a Sheet type
and the wizard then creates this sheet.
I am using this sheet for a Stock count on a Palmtop.If the user only has works then he can create a works sheet...
When the count is complete then the user imports the count data from the sheet.
xlAddInxlCSVxlCSVMacxlCSVMSDOSxlCSVWindowsxlDBF2xlDBF3xlDBF4xlDIFxlExcel2xlExcel2FarEastxlExcel3xlExcel4xlExcel5xlExcel4WorkbookxlIntlAddInxlIntlMacroxlWorkbookNormalxlSYLK      xlTemplatexlCurrentPlatformTextxlTextMacxlTextMSDOSxlTextPrinterxlTextWindowsxlWJ2WD1xlWK1xlWK1ALLxlWK1FMTxlWK3xlWK4xlWK3FM3xlWKSxlWorks2FarEastxlWQ1xlWJ3xlWJ3FJ3

Hi VB,

Try this:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook

Set xlApp=CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open "C:\MyDir\MyFile.xls"
xlBook.Sheets("Sheet1").Cells(1,1) = "Hello"
xlBook.SaveAs Filename:="text.xls",FileFormat:=xlWorkbookNormal 'see other constants below
xlBook.Close
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing



Constant you should use


xlExcel9795         Microsoft Excel 97
xlExcel5            Microsoft Excel 5.0/95 Workbook
xlExcel4            Microsoft Excel 4.0 Workbook
xlExcel3            Microsoft Excel 3.0 Worksheet
xlNormal            Microsoft Excel Workbook
xlWK4               WK4(1-2-3)
xlWK3               WK3(1-2-3)
xlWK1               WK1(1-2-3)
xlWKs               WKs(1-2-3)
xlText              Text (Tab Delimited)

Calacuccia
ASKER CERTIFIED SOLUTION
Avatar of calacuccia
calacuccia
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial