Page 1 of 1

dbf to xls file by macro

Posted: Mon Apr 02, 2018 2:45 am
by jackchan1026
hi...
how can i save as my dbf file to xls by macro?because i everyday need convert my dbf file to xls by manually..i hope can create like microsoft excel (xlsm)file then can.automatic convert...

Re: dbf to xls file by macro

Posted: Mon Apr 02, 2018 7:09 am
by jackchan1026
Sub auto_open()
Run "excelcopy"
End Sub

Sub excelcopy()
Dim x As Workbook
Dim y As Workbook

'## Open both workbooks first:
Set x = Workbooks.Open("C:\data\itemmas.dbf")
Set y = Workbooks.Open("C:\Users\Dropbox\backup\cs042018.csv")

'Now, copy what you want from x:
x.Sheets("CS042018").Range("A:A,B:B,M:M,O:O").Copy

'Now, paste to y worksheet:
y.Sheets("cs042018").Range("A1").PasteSpecial

y.Save


'Close x:
x.Close
y.Close False
Application.Quit

End Sub


please help me check any wrong of my code?

Re: dbf to xls file by macro

Posted: Mon Apr 02, 2018 7:30 am
by Zizi64
please help me check any wrong of my code?
What is wrong?! The whole code is wrong, because it is a VBA code. The VBA of the MS Office and the API+StarBasic combo of the AOO/LO are not compatible.
...And you want to convert a file into a foreign, never standardized file format. The AOO/LO works best in the native, International Standard ODF fileformats. (In this case: in .ods.) Use it.


Tips:
- You can try the LibreOffice. It has a littlebit higher compatibility with the foreign file formats, and with the VBA macros.

- Use the "Option VBA support 1" statement at the begin of your code. That "warns" the application to the foreign code elements.

- Rewrite your macro code based on the API function in StarBasic (or in an other supported language). API: Application Programming Interface.