Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Excel object - save as csv from Word?

From within a Word macro I'm trying to save an Excel object as a csv file,
but can't seem to find any documentation that explains how to do it. Any
ideas? Code below -- I've tried objExcel.dialogs(xlDialogSaveAs).show but
get an error saying that xlDialogSaveAs is an undefined variable, and when I
try to specify xlCSV as a file format I get the same undefined variable error:

sub SaveAsCSV()

Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Add

[snip - doing stuff to workbook]

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv"
'The above line saves as an .xls even if the suffix is ".csv"

objExcel.Application.Quit

Set objExcel = Nothing

end sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel object - save as csv from Word?

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv", Fileformat:=6

--
Regards,
Tom Ogilvy

"Chuck" wrote in message
...
From within a Word macro I'm trying to save an Excel object as a csv file,
but can't seem to find any documentation that explains how to do it. Any
ideas? Code below -- I've tried objExcel.dialogs(xlDialogSaveAs).show but
get an error saying that xlDialogSaveAs is an undefined variable, and when

I
try to specify xlCSV as a file format I get the same undefined variable

error:

sub SaveAsCSV()

Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Add

[snip - doing stuff to workbook]

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv"
'The above line saves as an .xls even if the suffix is ".csv"

objExcel.Application.Quit

Set objExcel = Nothing

end sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Excel object - save as csv from Word?

Hi Tom

Thanks for that -- it works. However, it seems that when I use that syntax,
if I save in any format other than an Excel format, I get a series of Excel
save as dialogs (warnings that the file exists, the Excel dialog itself, then
a warning about saving in a non Excel format) in addition to the Word dialog
pointing out that a file of the same name already exists (I want to
overwrite). Is there any way to avoid having all those Excel dialogs pop up?

Chuck



"Tom Ogilvy" wrote:

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv", Fileformat:=6

--
Regards,
Tom Ogilvy

"Chuck" wrote in message
...
From within a Word macro I'm trying to save an Excel object as a csv file,
but can't seem to find any documentation that explains how to do it. Any
ideas? Code below -- I've tried objExcel.dialogs(xlDialogSaveAs).show but
get an error saying that xlDialogSaveAs is an undefined variable, and when

I
try to specify xlCSV as a file format I get the same undefined variable

error:

sub SaveAsCSV()

Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Add

[snip - doing stuff to workbook]

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv"
'The above line saves as an .xls even if the suffix is ".csv"

objExcel.Application.Quit

Set objExcel = Nothing

end sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel object - save as csv from Word?

On error resume next
Kill "C:\Myfile.csv
On Error goto 0
objExcel..DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv",
Fileformat:=6"Chuck"
objExcel.ActiveWorkbook.Close SaveChanges:=False
objExcel.DisplayAlerts = True

--
Regards,
Tom Ogilvy


wrote in message
...
Hi Tom

Thanks for that -- it works. However, it seems that when I use that

syntax,
if I save in any format other than an Excel format, I get a series of

Excel
save as dialogs (warnings that the file exists, the Excel dialog itself,

then
a warning about saving in a non Excel format) in addition to the Word

dialog
pointing out that a file of the same name already exists (I want to
overwrite). Is there any way to avoid having all those Excel dialogs pop

up?

Chuck



"Tom Ogilvy" wrote:

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv", Fileformat:=6

--
Regards,
Tom Ogilvy

"Chuck" wrote in message
...
From within a Word macro I'm trying to save an Excel object as a csv

file,
but can't seem to find any documentation that explains how to do it.

Any
ideas? Code below -- I've tried objExcel.dialogs(xlDialogSaveAs).show

but
get an error saying that xlDialogSaveAs is an undefined variable, and

when
I
try to specify xlCSV as a file format I get the same undefined

variable
error:

sub SaveAsCSV()

Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Add

[snip - doing stuff to workbook]

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv"
'The above line saves as an .xls even if the suffix is ".csv"

objExcel.Application.Quit

Set objExcel = Nothing

end sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Excel object - save as csv from Word?

That's excellent, you're a star! ;) It's common sense really.

"Tom Ogilvy" wrote:

On error resume next
Kill "C:\Myfile.csv
On Error goto 0
objExcel..DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv",
Fileformat:=6"Chuck"
objExcel.ActiveWorkbook.Close SaveChanges:=False
objExcel.DisplayAlerts = True

--
Regards,
Tom Ogilvy


wrote in message
...
Hi Tom

Thanks for that -- it works. However, it seems that when I use that

syntax,
if I save in any format other than an Excel format, I get a series of

Excel
save as dialogs (warnings that the file exists, the Excel dialog itself,

then
a warning about saving in a non Excel format) in addition to the Word

dialog
pointing out that a file of the same name already exists (I want to
overwrite). Is there any way to avoid having all those Excel dialogs pop

up?

Chuck



"Tom Ogilvy" wrote:

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv", Fileformat:=6

--
Regards,
Tom Ogilvy

"Chuck" wrote in message
...
From within a Word macro I'm trying to save an Excel object as a csv

file,
but can't seem to find any documentation that explains how to do it.

Any
ideas? Code below -- I've tried objExcel.dialogs(xlDialogSaveAs).show

but
get an error saying that xlDialogSaveAs is an undefined variable, and

when
I
try to specify xlCSV as a file format I get the same undefined

variable
error:

sub SaveAsCSV()

Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Add

[snip - doing stuff to workbook]

objExcel.ActiveWorkbook.SaveAs FileName:="c:\myfile.csv"
'The above line saves as an .xls even if the suffix is ".csv"

objExcel.Application.Quit

Set objExcel = Nothing

end sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel object linked to word will not add sums in word Robin Excel Discussion (Misc queries) 0 March 31st 09 11:10 PM
PLS HELP! Excel imbedded object in Word dee Excel Discussion (Misc queries) 0 March 14th 07 01:21 PM
Print Word Object in Excel Mac Excel Discussion (Misc queries) 7 March 2nd 07 05:12 PM
TO MODIFY A EXCEL OBJECT FROM WORD USING VBA Sandra Bonilla Excel Programming 1 November 10th 04 03:59 AM
Using vb to create an excel object and save it as a CSV file eli silverman[_2_] Excel Programming 1 December 4th 03 10:15 PM


All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"