dbf to xls file by macro

Creating a macro - Writing a Script - Using the API

dbf to xls file by macro

Postby jackchan1026 » Mon Apr 02, 2018 2:45 am

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...
Last edited by robleyd on Mon Apr 02, 2018 4:03 am, edited 1 time in total.
Reason: Remove Known Issues icon [robleyd, Moderator]
openoffice 3.1
jackchan1026
 
Posts: 2
Joined: Mon Apr 02, 2018 2:38 am

Re: dbf to xls file by macro

Postby jackchan1026 » Mon Apr 02, 2018 7:09 am

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?
openoffice 3.1
jackchan1026
 
Posts: 2
Joined: Mon Apr 02, 2018 2:38 am

Re: dbf to xls file by macro

Postby Zizi64 » Mon Apr 02, 2018 7:30 am

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.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.1 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.2 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7308
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: OldStd and 7 guests