
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Exporting into txt file after exporting into excel
Hi
How to export a table into excel and then exporting the same from excel to text file using macro. Please help!
Thanks,
qvforum
- « Previous Replies
-
- 1
- 2
- Next Replies »

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe something like this:
XLSFile = "test.xls"
TXTFile= "test.txt"
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelDoc = objExcelApp.Workbooks.Add
set xlSheet = objExcelDoc.Sheets("Sheet1")
ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard true
XLDoc.Sheets(j).Range("A" & 1).Select
XLDoc.Sheets(j).Paste
objExcelDoc.SaveAs XLSFile, 56 'save as xls
objExcelDoc.SaveAs TXTFile, -4158 'save as txt
objExcelDoc.Close
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Object required: 'XLDoc'
I tried to execute something like below but getting the above error. Could you please help me out one this?
Sub Test
XLSFile = "test.xls"
TXTFile= "test.txt"
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelDoc = objExcelApp.Workbooks.Add
set xlSheet = objExcelDoc.Sheets("Sheet1")
ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard true
XLDoc.Sheets(j).Range("A" & 1).Select
XLDoc.Sheets(j).Paste
objExcelDoc.SaveAs XLSFile, 56 'save as xls
objExcelDoc.SaveAs TXTFile, -4158 'save as txt
objExcelDoc.Close
End Sub
Also what I have noticed is that you are exporting one in xls and other in txt. But what I need is to export first in xls then from xls export it in txt. Hope it is clear now!
Thanks
qvforum

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops, my bad. I should learn to copy-paste properly. XLDoc should be objExcelDoc.
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sub TestXLSFile = "test.xls"
TXTFile= "test.txt"Set objExcelApp = CreateObject("Excel.Application")
Set objExcelDoc = objExcelApp.Workbooks.Add
set xlSheet = objExcelDoc.Sheets("Sheet1")ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard true
objExcelDoc.Sheets(j).Range("A" & 1).Select
objExcelDoc.Sheets(j).PasteobjExcelDoc.SaveAs XLSFile, 56 'save as xls
objExcelDoc.SaveAs TXTFile, -4158 'save as txt
objExcelDoc.CloseEnd Sub
After doing above changes getting the following error message
Subscript out of range
Any help please!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This works for me.
Change the locations of the files, the objectname you want to export (mine is TB01), and the name of the sheet if you're using the english version of excel. My dutch version needs Blad1 instead of Sheet1
Sub Test
XLSFile = "C:\Temp\test.xls"
TXTFile= "C:\Temp\test.txt"
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelDoc = objExcelApp.Workbooks.Add
set xlSheet = objExcelDoc.Sheets("Sheet1")
ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard true
xlSheet.Range("A1").Select
xlSheet.Paste
objExcelApp.DisplayAlerts = false
objExcelDoc.SaveAs XLSFile
objExcelDoc.SaveAs TXTFile, -4158
objExcelDoc.Close
objExcelApp.DisplayAlerts = true
End Sub
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works but it is not giving the required output
Original data:
File | Location |
Development | "C:\temp" |
Output:
File Location
Development """C:\temp"""
It has added double double quotes at the start and end. This is what the problem I am facing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, well this won't solve that problem. But why don't you strip the quotes from the locations first, either on load or in the table you want to export?
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Due to some reasons I cannot remove the quotes! That's the problem here...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The quotes MUST be displayed in your qlikview application!? Wow. Oh, well. Create a chart then that you use only for export, not display (maybe hide it on a hidden sheet). In that chart you can remove the quotes from the location strings.
talk is cheap, supply exceeds demand

- « Previous Replies
-
- 1
- 2
- Next Replies »