Results 1 to 10 of 86

Thread: Copy Paste based on comparisons calculations in 2 XL files, 1 might be .csv file .Opened in XL=Fail/Chaos

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    I try again to explain..

    You can Open and Set a workbook like these. These all open a workbook. But they will error if the workbook is already open - That is obvious: You cannot open if it is already open!
    Code:
    '  http://www.excelfox.com/forum/showthread.php/2421-copy-and-paste?p=13029&viewfull=1#post13029
    Sub OpenAndSetWorkbook()
    Dim Wb As Workbook
     Workbooks.Open Filename:="C:\ ........ MyFile.xls"               '  or Workbooks.Open "C:\ ........ MyFile.xls"
    
    ' Workbook "MyFile.xls" is now open ( and active*** )
     Set Wb = ActiveWorkbook ' The workbook just opened will be the active*** workbook
    End Sub
    
    Sub SetAndOpenWorkbook()
    Dim Wb As Workbook
    ' Open and Set in same code line:
     Set Wb = Workbooks.Open("C:\ ........ MyFile.xls") ' this will Open and Set in same code line
    End Sub
    
    Sub OpenAndSetWorkbook_()
    Dim Wb As Workbook
     Workbooks.Open Filename:="C:\ ........ MyFile.xls"           '  or Workbooks.Open "C:\ ........ MyFile.xls"
      
    ' Workbook "MyFile.xls" is now open ( and active )                                           If the workbook is already open , then we can refer to it using the workbooks collection object of open workbooks,  Workbooks(" ")
     Set Wb = Workbooks("MyFile.xls") ' Use workbooks collection object of open workbooks,  Workbooks(" ")  to reference already open workbooks
    End Sub



    If the workbook is already open , then we can refer to it using the workbooks collection object of open workbooks, Workbooks(" ")

    Code:
    Sub SetToAlreadyOpenWorkbook()
    ' For this to work,  MyFile.xls   must already be open
    Dim Wb As Workbook
     
    ' If the workbook is already open , then we can refer to it using the workbooks collection object of open workbooks,  Workbooks(" ")
     Set Wb = Workbooks("MyFile.xls") ' Uses workbooks collection object of open workbooks,  Workbooks(" ")  to reference already open workbooks
    End Sub
    Last edited by DocAElstein; 04-02-2020 at 12:21 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 26
    Last Post: 09-26-2020, 05:56 PM
  2. Copy paste data based on criteria
    By analyst in forum Excel Help
    Replies: 7
    Last Post: 01-13-2014, 12:46 PM
  3. Replies: 8
    Last Post: 10-31-2013, 12:38 AM
  4. Replies: 2
    Last Post: 09-18-2013, 12:30 AM

Tags for this Thread

Posting Permissions

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