Temporary-Failure
Board Regular
- Joined
- Jul 16, 2010
- Messages
- 140
I have workbook Laskutusohjelma.xls where is button which runs macro called "Check" and opens also Varastohallinta.xls file. In the Varastohallinta.xls there is a code in the ThisWorkbook:
Teecsv is in module in the Varastohallinta.xls:
If I run teecsv macro directly in the Varastohallinta.xls it works perfectly but If I run Check-macro in the Laskutusohjelma, then teecsv runs through but it doesn't do anything, not a single line what is in the teecsv-macro. Why?
Code:
Public Sub Workbook_BeforeClose(Cancel As Boolean)
Call teecsv
Worksheets("Varastohallinta").Activate
ActiveWorkbook.Save
Me.Saved = True
End Sub
Teecsv is in module in the Varastohallinta.xls:
Code:
Public Sub teecsv()
Workbooks("Varastokirjanpito.xls").Activate
Workbooks("Varastokirjanpito.xls").Sheets("Omat").Select
Columns("A:K").Select
Selection.ClearContents
Range("A1").Select
Sheets("Varastohallinta").Select
Range("P2:P1838").Select
Selection.Copy
Workbooks("Varastokirjanpito.xls").Sheets("Omat").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'MsgBox LastRow
Range("A" & LastRow).Select
'----------------------------------------------------------------------------------------------
Workbooks("Varastokirjanpito.xls").Sheets("Varastohallinta").Select
Range("Q2:Q1838").Select
Selection.Copy
Workbooks("Varastokirjanpito.xls").Sheets("Omat").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'MsgBox LastRow
Range("A" & LastRow).Select
'----------------------------------------------------------------------------------------------
Workbooks("Varastokirjanpito.xls").Sheets("Varastohallinta").Select
Range("R2:R1838").Select
Selection.Copy
Workbooks("Varastokirjanpito.xls").Sheets("Omat").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'MsgBox LastRow
Range("A" & LastRow).Select
'----------------------------------------------------------------------------------------------
Workbooks("Varastokirjanpito.xls").Sheets("Varastohallinta").Select
Range("S2:S1838").Select
Selection.Copy
Workbooks("Varastokirjanpito.xls").Sheets("Omat").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'MsgBox LastRow
'----------------------------------------------------------------------------------------------
Workbooks("Varastokirjanpito.xls").Sheets("Varastohallinta").Select
Range("T2:T1838").Select
Selection.Copy
Workbooks("Varastokirjanpito.xls").Sheets("Omat").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'MsgBox LastRow
Range("A1" & ":" & "A" & LastRow).Select
Selection.Value = Selection.Value
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Range("A1").Select
Application.DisplayAlerts = False
ChDir _
"E:\Copiot O - V\Omat tiedostot\Yritys\Verkkokauppa Clover Shop Pro\Nettihotellipalvelimelta imutettu verkkokauppa\CSV"
ActiveWorkbook.SaveAs Filename:= _
"E:\Copiot O - V\Omat tiedostot\Yritys\Verkkokauppa Clover Shop Pro\Nettihotellipalvelimelta imutettu verkkokauppa\CSV\Omat.prn" _
, FileFormat:=xlTextPrinter, CreateBackup:=False
ChDir "E:\Copiot O - V\Omat tiedostot\Yritys\Laskut ja kuitit"
ActiveWorkbook.SaveAs Filename:= _
"E:\Copiot O - V\Omat tiedostot\Yritys\Laskut ja kuitit\Varastokirjanpito.xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
GivenLocation = "E:\Copiot O - V\Omat tiedostot\Yritys\Verkkokauppa Clover Shop Pro\Nettihotellipalvelimelta imutettu verkkokauppa\CSV\" 'note the trailing backslash
OldFileName = "Omat.prn"
NewFileName = "Omat.csv"
If Dir(GivenLocation & NewFileName) <> "" Then
GoTo remove
Else
GoTo teeuusi
End If
remove:
Kill GivenLocation & NewFileName
teeuusi:
Name GivenLocation & OldFileName As GivenLocation & NewFileName
Call uploadcsv
Application.DisplayAlerts = True
Workbooks("Varastokirjanpito.xls").Sheets("Varastohallinta").Select
Range("C1").Select
End Sub
If I run teecsv macro directly in the Varastohallinta.xls it works perfectly but If I run Check-macro in the Laskutusohjelma, then teecsv runs through but it doesn't do anything, not a single line what is in the teecsv-macro. Why?
Last edited: