Makro wczytujące CSV
: pt maja 13, 2016 10:40 am
Witam
mam makro które wczytuje plik csv, i to działało mi na windows7 po przeniesieniu tego makra na Windows8 wyskakuje mi błąd:
"Błąd uruchomieniowy Języka Basic.
Nie ustawiono zmiennej obiektu"
i zaznacza linię
oActiveCell = oDoc.CurrentSelection
w czym jest problem?
Makro :
sub Main
Dim oDoc as variant
dim oActiveCell as object
dim oArkusz, oArkusz2 as object
dim iNumber, granica,powtorzen,dosumowania,bazaj as integer
dim oZakres1, oReplace as object
Dim aSortFields(3) As New com.sun.star.util.SortField
Dim aSortFields2(1) As New com.sun.star.util.SortField
Dim aSortAscend(0) As New com.sun.star.beans.PropertyValue
Dim oCell, oCell4 As Object
Dim oCursor, oCursor1 As Object
Dim aAddress As Variant
Dim LocalSettings As new com.sun.star.lang.Locale
Dim NumberFormatId as long
Dim filterNames(0) As String
Dim oFileDialog as Object
Dim iAccept as Integer
Dim sPath, sLine as String
Dim args1(3) As New com.sun.star.beans.PropertyValue
GlobalScope.BasicLibraries.LoadLibrary("Tools")
LocalSettings.Language = "pl"
LocalSettings.Country = "pl"
NumberFormatId = ThisComponent.NumberFormats.queryKey("###0,00;[RED]-###0,00", LocalSettings,True)
If NumberFormatId = -1 then
NumberFormatId = ThisComponent.NumberFormats.addNew("###0,00;[RED]-###0,00", LocalSettings)
end if
NumberFormatIdDaty = ThisComponent.NumberFormats.queryKey("DD.MM.YYYY", LocalSettings,True)
If NumberFormatIdDaty = -1 then
NumberFormatIdDaty = ThisComponent.NumberFormats.addNew("DD.MM.YYYY", LocalSettings)
end if
if ThisComponent.Sheets.hasByName("F") then
oArkusz2 = ThisComponent.Sheets.getByName("F")
Else
oArkusz2 = ThisComponent.createInstance("com.sun.star.sheet.Spreadsheet")
ThisComponent.Sheets.insertByName("F", oArkusz2)
end if
oArkusz2.Rows.removeByIndex(0,64000)
filterNames(0) = "*.csv"
oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
AddFiltersToDialog(filterNames(), oFileDialog )
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
sPath = oFileDialog.Files(0)
GetAFileName = sPath
End If
oFileDialog.Dispose()
args1(0).Name = "InteractionHandler"
args1(0).Value = ""
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "CharacterSet"
args1(2).Value = 13 ' ISO-8859-2
args1(3).Name = "FilterOptions" ' opcje importu
args1(3).Value = "44,34,0,1,1/2/2/2/3/2/4/2/5/2/6/2/7/2/8/2/9/2/10/5"
oDesk = createUnoService("com.sun.star.frame.Desktop")
oDoc = oDesk.LoadComponentFromURL( GetAFileName, "_blank", 0, args1())
oActiveCell = oDoc.CurrentSelection
oCursor = oDoc.Sheets(0).createCursorByRange(oActiveCell)
oCursor.GotoEndOfUsedArea(True)
aAddress = oCursor.RangeAddress
oZakres1 = oArkusz2.getCellRangeByPosition(9,0,9,aAddress.EndRow)
oZakres1.NumberFormat = NumberFormatIdDaty
oZakres1 = oDoc.Sheets(0).getCellRangeByPosition(0,0,aAddress.EndColumn,aAddress.EndRow)
oZakres2 = oArkusz2.getCellRangeByPosition(0,0,aAddress.EndColumn,aAddress.EndRow)
oZakres2.setDataArray(oZakres1.getDataArray())
oDoc.close(true)
End sub
mam makro które wczytuje plik csv, i to działało mi na windows7 po przeniesieniu tego makra na Windows8 wyskakuje mi błąd:
"Błąd uruchomieniowy Języka Basic.
Nie ustawiono zmiennej obiektu"
i zaznacza linię
oActiveCell = oDoc.CurrentSelection
w czym jest problem?
Makro :
sub Main
Dim oDoc as variant
dim oActiveCell as object
dim oArkusz, oArkusz2 as object
dim iNumber, granica,powtorzen,dosumowania,bazaj as integer
dim oZakres1, oReplace as object
Dim aSortFields(3) As New com.sun.star.util.SortField
Dim aSortFields2(1) As New com.sun.star.util.SortField
Dim aSortAscend(0) As New com.sun.star.beans.PropertyValue
Dim oCell, oCell4 As Object
Dim oCursor, oCursor1 As Object
Dim aAddress As Variant
Dim LocalSettings As new com.sun.star.lang.Locale
Dim NumberFormatId as long
Dim filterNames(0) As String
Dim oFileDialog as Object
Dim iAccept as Integer
Dim sPath, sLine as String
Dim args1(3) As New com.sun.star.beans.PropertyValue
GlobalScope.BasicLibraries.LoadLibrary("Tools")
LocalSettings.Language = "pl"
LocalSettings.Country = "pl"
NumberFormatId = ThisComponent.NumberFormats.queryKey("###0,00;[RED]-###0,00", LocalSettings,True)
If NumberFormatId = -1 then
NumberFormatId = ThisComponent.NumberFormats.addNew("###0,00;[RED]-###0,00", LocalSettings)
end if
NumberFormatIdDaty = ThisComponent.NumberFormats.queryKey("DD.MM.YYYY", LocalSettings,True)
If NumberFormatIdDaty = -1 then
NumberFormatIdDaty = ThisComponent.NumberFormats.addNew("DD.MM.YYYY", LocalSettings)
end if
if ThisComponent.Sheets.hasByName("F") then
oArkusz2 = ThisComponent.Sheets.getByName("F")
Else
oArkusz2 = ThisComponent.createInstance("com.sun.star.sheet.Spreadsheet")
ThisComponent.Sheets.insertByName("F", oArkusz2)
end if
oArkusz2.Rows.removeByIndex(0,64000)
filterNames(0) = "*.csv"
oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
AddFiltersToDialog(filterNames(), oFileDialog )
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
sPath = oFileDialog.Files(0)
GetAFileName = sPath
End If
oFileDialog.Dispose()
args1(0).Name = "InteractionHandler"
args1(0).Value = ""
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "CharacterSet"
args1(2).Value = 13 ' ISO-8859-2
args1(3).Name = "FilterOptions" ' opcje importu
args1(3).Value = "44,34,0,1,1/2/2/2/3/2/4/2/5/2/6/2/7/2/8/2/9/2/10/5"
oDesk = createUnoService("com.sun.star.frame.Desktop")
oDoc = oDesk.LoadComponentFromURL( GetAFileName, "_blank", 0, args1())
oActiveCell = oDoc.CurrentSelection
oCursor = oDoc.Sheets(0).createCursorByRange(oActiveCell)
oCursor.GotoEndOfUsedArea(True)
aAddress = oCursor.RangeAddress
oZakres1 = oArkusz2.getCellRangeByPosition(9,0,9,aAddress.EndRow)
oZakres1.NumberFormat = NumberFormatIdDaty
oZakres1 = oDoc.Sheets(0).getCellRangeByPosition(0,0,aAddress.EndColumn,aAddress.EndRow)
oZakres2 = oArkusz2.getCellRangeByPosition(0,0,aAddress.EndColumn,aAddress.EndRow)
oZakres2.setDataArray(oZakres1.getDataArray())
oDoc.close(true)
End sub