Consulting

Results 1 to 2 of 2

Thread: problem with closing WB when copying data from on WB to another

  1. #1

    problem with closing WB when copying data from on WB to another

    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 !
    Last edited by Bob Phillips; 02-04-2015 at 07:21 AM. Reason: Added code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
        Application.DisplayAlerts = False
        
         'Close the workbook without saving it
        Workbooks("Mislykkedesfebruar2015").Close savechanges:=False
        Application.DisplaAlaerts = True
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •