Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    1. Every variable must be explicitly declared or it defaults to variant type

    2. Quite should be Quit. Did you run debug compile?



    3. Your looping code doesn't make sense to me.

    4. Can only get code to copy between workbooks in same instance of Excel to work, as in the following:

    Code:
    Sub CopySheet()
    Dim xl As Excel.Application, xlw1 As Excel.Workbook, xlw2 As Excel.Workbook
    Dim x As Integer
    Set xl = CreateObject("Excel.Application")
    Set xlw2 = xl.Workbooks.Add
    For x = 1 To 100
        Set xlw1 = xl.Workbooks.Open("C:\path\filename.xlsx", , True)
        xlw1.Sheets(1).Copy After:=xlw2.Sheets(xlw2.Sheets.Count)
        xlw2.ActiveSheet.Name = "T" & x & Left(xlw1.Name, InStr(xlw1.Name, ".") - 1)
        xlw1.Close
    Next
    xl.Visible = True
    End Sub
    5. I can manually open and close Excel while code is running and VBA Excel object remains not visible until the line to set visible.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    I did what you did with your example, x1 as both the open file and the Added new file before turning it into (what I posted) x1, and x2 as separate instance.
    With x1 as the same instance, the issue that the added file, along with the open file becomes visible is still an issue. This is especially when I open a file (the
    file in the directory that is running ) in the directory.

    The looping is just to loop until end of file (maybe I typed/ copied it wrong). Quite is a typo.

    I tested your code and I see the issue occurred. While is running I open filename the added file along with the open file becomes visible.
    And I get an error message too. Click image for larger version. 

Name:	CAPTURE 042918.GIF 
Views:	13 
Size:	25.0 KB 
ID:	33803
    I don't know if the option explicit would help with it (I may try out).

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    I don't have several hundred workbooks to test Do Loop code. My code uses the same workbook to copy from for 100 iterations. I even manually open that wb while code executes. Cannot replicate issue. Perhaps I don't understand process you are trying to accomplish.

    I just noticed in your posted code the variable P is not set
    How does it get value? I also don't see how the code is cycling through files.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #19
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    You could create one file with data, copy it and repeat.
    It grows exponentially really quickly. Soon I will have hundreds.

    Sorry P is really path.

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Could, but don't really want to.

    Well, I ran code again. Did get that popup error. Killed code and tried again. Did not get error.

    Okay, modified test. Ran code and opened some other totally unrelated Excel file. That does cause the Excel files to be visible. Tried again, files did not become visible.

    Cannot replicate issue consistently so probably cannot help.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    Alright no problem - I wonder why issue is not consistent.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-14-2017, 07:31 AM
  2. Replies: 2
    Last Post: 06-25-2014, 10:29 PM
  3. Replies: 1
    Last Post: 05-20-2013, 01:50 PM
  4. Replies: 1
    Last Post: 01-22-2013, 09:51 AM
  5. Replies: 1
    Last Post: 09-27-2010, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums