Hi, everyone.
I'm using PB 2019.
I made a datawindow with no column head.
I try to save the datawindow to excel file 'empty.xls'.
After saving, I try to copy all rows in sheet1 of 'empty.xls' and paste it to another excel file 'forms.xls'.
I wrote titles of each columns in first row of 'forms.xls'.
So I try to paste it from on second row in sheet1 of 'forms.xls'.
The scripts are as below.
------------------------------------------------------------------------------------------------------------------------
OleObject myoleobject
Int rtn
String ls_file, ls_file_1, ls_title_excel_nm, ls_title_sheet_nm
ls_file = GetCurrentDirectory() + "\empty.xls"
myOleObject = Create OleObject
rtn = myoleobject.ConnectToNewObject("excel.application")
dw_list.SaveAsAscii(ls_file,"~t","")
myOleObject.Application.Visible = False
IF rtn = 0 THEN
myOleObject.WorkBooks.Open(ls_file)
ls_file_1 = GetCurrentDirectory() + "\forms.xls"
myOleObject.WorkBooks.Open(ls_file_1)
ELSE
Messagebox("!", "Failed!")
Destroy myoleobject
Return
End If
Long li_F_Row_Start, li_F_Row_End, li_T_Row_Start, li_T_Row_End
String ls_Copy_Rows, ls_Paste_Rows
li_F_Row_Start = 1
li_F_Row_End = dw_list.rowcount()
li_T_Row_Start = li_F_Row_Start + li_title_rows
li_T_Row_End = li_F_Row_End + li_title_rows
ls_Copy_Rows = String(li_F_Row_Start) + ':' + String(li_F_Row_End)
ls_Paste_Rows = String(li_T_Row_Start) + ':' + String(li_T_Row_End)
myoleobject.Application.Workbooks('empty.xls').WorkSheets(1).Activate
myoleobject.Application.Workbooks('empty.xls').WorkSheets(1).Rows(ls_Copy_Rows).Select
myoleobject.Application.Selection.Copy
myoleobject.Application.Workbooks('forms.xls').WorkSheets(1).Activate
myoleobject.Application.Workbooks('forms.xls').ActiveSheet.Rows(ls_Paste_Rows).PasteSpecial(-4163, -4142, false, false)
myoleobject.Application.CutCopyMode = False
myoleobject.Application.Workbooks('empty.xls').close
myOleObject.Application.Visible = True
myoleObject.windowstate = 3
DESTROY myOleObject
------------------------------------------------------------------------------------------------------------------------
This is working well on PC with Excel version 2013, OS Win 11.
But on PC with Excel 2019 OS Win 11, error has occured like this.
"Error accessing external object property select at line 00"
Is VBA ".select" not works with Excel 2019 ??
I'm looking forward to your help.
Thanks.
and the VBA after edit the macro is as below
-------------------------------------------------------------
Sub Macro_test()
Rows("1:15").Select
Selection.Copy
End Sub
-------------------------------------------------------------
I don't know the difference between this and my scripts.