PDA

View Full Version : [SOLVED] problem with closing WB when copying data from on WB to another



niklasbp
02-04-2015, 06:45 AM
Hi there

i have this code


Sheets.Add.name = "Mislykkedes"
Dim wbCopy As Workbook
Dim wsCopy As Worksheet
Dim rngCopy As Range
Dim wbPaste As Workbook
Dim wsPaste As Worksheet
Dim rngPaste As Range


Set wbCopy = Workbooks.Open("C:\Users\Mikkel\Desktop\Rapporter_2015\Februar\Mislykkedesfebruar2015.xlsb") 'path
Set wsCopy = wbCopy.Worksheets("mislykkedes")
Set rngCopy = wsCopy.Range("A:Z").EntireColumn
Windows("Book1").Activate
Set wbPaste = ActiveWorkbook
Set wsPaste = wbPaste.Worksheets("mislykkedes")
Set rngPaste = wsPaste.Range("a1")

rngCopy.Copy
rngPaste.PasteSpecial

'Close the workbook without saving it
Workbooks("Mislykkedesfebruar2015").Close savechanges:=False


the problem is when i run the macro it ask's me if i want to use the data i have in my clipboard before i close the WB "mislykkedesfebruar2015"
how can i get around this?

hope you can help this is really bugging me !

Bob Phillips
02-04-2015, 07:22 AM
Application.DisplayAlerts = False

'Close the workbook without saving it
Workbooks("Mislykkedesfebruar2015").Close savechanges:=False
Application.DisplaAlaerts = True