Copying file

Please post any questions regarding the program here.

Moderator: 2020vision

Copying file

Postby Roadhouse » Thu Jul 23, 2015 2:32 pm

Hi has anyone had this problem?

I'm trying to copy the excel workbook files while they are linked to gruss I have 8 workbooks A.xlsm to H1.xlsm linked to 8 tabs but when it is linked to gruss it only copies the workbook on the first tab A1.xlsm and not the others.

If I unhook all 8 workbooks all 8 get copied fine can anyone help with this ?
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm

Re: Copying file

Postby osknows » Thu Jul 23, 2015 3:14 pm

Assuming you mean copying the file (rather than copying the contents of a sheet) you can use SaveCopyAs so that the original remains allowing it to stay connected to Gruss.

Code: Select all
Option Explicit

Sub test()
Dim i As Long
Dim wbArray(1 To 7) As Workbook
Dim fileName As String

    'Assume workbook filenames are Workbook1.xlsm to Workbook8.xlsm

    'Load workbooks to Array
    For i = LBound(wbArray, 1) To UBound(wbArray, 1)
        fileName = Replace("C:\Users\o\Desktop\New folder\Workbook{0}.xlsm", "{0}", i)
        Set wbArray(i) = GetObject(fileName)
    Next i
   
    'Save copy of workbooks with timestamp
    For i = LBound(wbArray, 1) To UBound(wbArray, 1)
        fileName = Replace(wbArray(i).FullName, ".", "_" & Format(Now, "yyyymmdd") & ".")
        wbArray(i).SaveCopyAs (fileName)
    Next i
   
'    'CleanUp if needed
'    For i = LBound(wbArray, 1) To UBound(wbArray, 1)
'        wbArray(i).Close
'        Set wbArray(i) = Nothing
'    Next i
   
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: Copying file

Postby Roadhouse » Thu Jul 23, 2015 3:42 pm

Hi thanks Osknows for your help, I put the code into a module set up workbook1 and workbook2 to gruss but the code highlighted getobject workbook name as an error?
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm

Re: Copying file

Postby osknows » Thu Jul 23, 2015 3:46 pm

Have you changed the path?

This is specific to me: "C:\Users\o\Desktop\New folder\Workbook{0}.xlsm"
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: Copying file

Postby Roadhouse » Thu Jul 23, 2015 3:55 pm

I made it this

Code: Select all
fileName = Replace("C:\Users\Administrator\Downloads\New folder\Workbook{0}.xlsm", "{0}", i)
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm

Re: Copying file

Postby osknows » Thu Jul 23, 2015 4:47 pm

What is the exact error? I just hooked up 8 sheets separately to Gruss and it worked okay this end.
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: Copying file

Postby Roadhouse » Thu Jul 23, 2015 5:55 pm

hi Os it says runtime error 432 and highlights Set wbArray(i) = GetObject(fileName)
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm

Re: Copying file

Postby osknows » Thu Jul 23, 2015 6:04 pm

Have you changed

Dim wbArray(1 To 7) As Workbook
to
Dim wbArray(1 To 2) As Workbook

to only load two workbooks instead of 7?
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: Copying file

Postby Roadhouse » Thu Jul 23, 2015 6:12 pm

hi I changed it to two workbooks and same error came up
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm

Re: Copying file

Postby osknows » Thu Jul 23, 2015 6:26 pm

The only thing that can cause error 432 is an incorrect filename or path https://msdn.microsoft.com/en-us/librar ... 09(v=vs.60).aspx

Double check the path is correct. Right click on the file and open properties and check the full path and filename with extension. Then put a breakpoint on line Set wbArray(i) = GetObject(fileName) and when the code stops check the above line to see what values the filepath is held in the variable fileName.
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: Copying file

Postby osknows » Thu Jul 23, 2015 6:27 pm

Eg, are your files .xls? The current code is checking for .xlsm
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Re: Copying file

Postby Roadhouse » Thu Jul 23, 2015 8:10 pm

No they are xlsm, I put workbook1 and workbook2 and the worksheet with the copy code in the same file downloads
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm

Re: Copying file

Postby Roadhouse » Thu Jul 23, 2015 11:49 pm

Hi Osknows I've got it to work thanks for your help
Roadhouse
 
Posts: 98
Joined: Fri Mar 02, 2012 7:01 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 59 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.