Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Select-method not working in macro

Hi everybody,

I have a problem again. On Friday I prepare a macro where I open an exsisted excel file, drop a table on a sheet and close the file while saving with another name. It has worked.

Than I reload the script on saturday, but nothing is happend Now the script shows me the error "select-method of the range-object could not be implenemt".

Makro.png

If I worte for the range cell, could the object not be suported. What's wrong with the code?

Regards Vicky

1 Solution

Accepted Solutions
Not applicable
Author

as i see you can add one extra line

Set objCurrentSheet = objExcelDoc.Sheets("Datenblatt")

objExcelDoc.Sheets("Datenblatt").Select

objExcelDoc.Sheets("Datenblatt").Range("A1").Select

this should help you

View solution in original post

19 Replies
Not applicable
Author

could you paste ExportExel macro code here?

Not applicable
Author

Here you are,

sub ExportExcel()
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = false
objExcelApp.DisplayAlerts = false      

Set objExcelDoc = objExcelApp.Workbooks.Open("K:\Test.xlsx")

Set SheetObj = ActiveDocument.GetSheetObject("CH09")     
SheetObj.CopyTableToClipboard true 

Set objCurrentSheet = objExcelDoc.Sheets("Datenblatt")
objExcelDoc.Sheets("Datenblatt").Range("A1").Select
objExcelDoc.Sheets("Datenblatt").Paste
objExcelDoc.Sheets("Datenblatt").Range("B:AP").NumberFormatLocal = "#.##0,00"
objExcelDoc.Sheets("Datenblatt").Range("D:D").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("G:G").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("J:J").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("M:M").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("P:P").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("S:S").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("V:V").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("Y:Y").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("AB:AB").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("AE:AE").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("AH:AH").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("AK:AK").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("AN:AN").NumberFormatLocal = "#.##0,00%"
objExcelDoc.Sheets("Datenblatt").Range("AQ:AQ").NumberFormatLocal = "#.##0,00%"

objExcelApp.ActiveWorkbook.SaveAS ("K:\Test_"&MonthName(date())&"_"&year(date())&".xlsx")
objExcelDoc.Close
objExcelApp.Quit
End sub



Anonymous
Not applicable
Author

Just a question, how is the macro triggered?

Not applicable
Author

Hi,

with a trigger in the document setting.

The first choose (during script execution) -> start macro.

The QV-File does triggered with the task scheduler from mircosoft.

Anonymous
Not applicable
Author

Ok, so if I understand correctly then you are not using QV-server or Publisher to reload the .qvw?

And, what version of QV are you using (just another check)?

Not applicable
Author

No, I'm not using QV-Server or Publisher. I only have single-user licence at the moment.

The version is 11.00.11154.0

flipside
Partner - Specialist II
Partner - Specialist II

Hi Vicky,

If you try to open the Test.xlsx document does it report the file is locked for editing?  Also check Task Manager for any running Excel applications.

You will need add set objExcelApp = Nothing to the last line of your code to release the Excel object to prevent this.

Hope this works

flipside

Not applicable
Author

This is not solving my problem. If I set objExcelApp.Visible = true and comment the with the objExcelDoc-part out, the excel file will be opened and save with the different name as desired. there is also no runny excel application in task manager. All is fine, but with the objExcelDoc-part nothing happens.

Not applicable
Author

does your K:\Test.xlsx file contain only plain text? or images to?

check if there are no merged cells