Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open File location 1

Status
Not open for further replies.

ameedoo3000

IS-IT--Management
Sep 20, 2016
233
EG
Hi all
i want to copy my table.dbf to Excel file by code .but i want to open location to save the file . how that?
i was use "copy to c:\table_name.xls type xl5" . now i want to open the any location to save the file."by code".
Greetings
Ahmed

 
Do you mean that you want to actually open the Excel file within Excel?

If so, the best way is to use ShellExecute(). If you don't know how to do that, see:


If that's not what you mean, please clarify your question.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I think the OP wants his end user to be able to select the destination for the xls file.


Code:
	PRIVATE m.FILENAME
	m.FILENAME = GETFILE("XLS","File Name","Select")
	IF !EMPTY(m.FILENAME)
		COPY TO (m.FILENAME) type xl5
	ENDIF

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
It certainly is Mike

B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
many thanks for all
i use this code
PRIVATE m.FILENAME
m.FILENAME = GETFILE("XLS","File Name","Save")
IF !EMPTY(m.FILENAME)
COPY TO (m.FILENAME) type xl5
ENDIF
and i have got my goal
thank you very much Griff and Mike.
greetings
Ahmed
 
Guys, GETFILE is to pick a file, there is PUTFILE() to get a better suitable dialog for asking the user to specify directory and name for a new file.

Besides that, if you want users to see the file in Excel you can copy over your data to Excel itself with OLE automation of Excel.Application and make your Workbook visible in Excel, even before it's saved. Then users can use the save dialog of Excel, as they are used to, get the alert of Excel when closing it without saving, save in current Excel format, etc. etc.

Code:
SELECT yourtable
Copy2Excel()
&& or Copy2Excel(aliasname)

Procedure Copy2Excel()
    Lparameters tcAlias
    tcAlias = Evl(tcAlias,Alias())
    Select * From (tcAlias) into Array paExcel

    Local loExcel
    loExcel = CreateObject("Excel.Application")
    =loExcel.Workbooks.Add()
    With loExcel.ActiveWorkbook.ActiveSheet
       With .Range(.Cells(1,1),.Cells(Alen(paExcel,1),Alen(paExcel,2)))
          .Value = ExecScript("LParameters tcArrayName"+Chr(13)+"Return @&tcArrayName",'paExcel')
          .Columns.AutoFit()
       EndWith 
    EndWith 
    loExcel.Visible = .t.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Well, it starts with the title caption of PUTFILE() being "Save as" automatically while you need to provide all parameters of GETFILE() to pass in the last one for the title bar caption. You can provide a new name, too, that's ok.

Bye, Olaf.


Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top