AutoData2012
10-23-2012, 06:19 PM
I'm on office 2007 at work, and I am working on a solution to automate some standard tasks. These tasks involve, web, word, excel and access. I have figured out most of what needs to be done, except for one major issue.
The problem comes in when I download the query results from our web application. The results are downloaded into an excel based document, but the document does not register under the excel.applications. When I review the path and name of the object after it is downloaded they are both HTML references. I have looked for a temporary path to the file but I can't find it actually being saved anywhere.
If it were a simple excel document, I could locate it by name, path or I could easily loop through the Excel.Application object and find it, or use the GetObject command. But none of those work:
'With this the file is never found
For each w in Excel.Application.Workbooks
If w.Name = ExpectedFileName then
Set wbook = w
Exit For
endif
Next w
I have tried using the TASKS collection in word, and I can locate it with a simple loop, but I can't do anything useful once I have found it. I have tried setting a workbook variable to the task, but that always results in the variable being set to nothing:
'Results in wbook being set to nothing
For each T in Tasks
If T.visible = True and T.Name = ExpectedFileName then
Set wbook = T
Exit For
EndIf
Next T
I have considered going old school and using a send keys string with pauses in the appropriate locations to allow the file to be saved. The problem I have with this is that there are many different reports, many different sizes, so waiting a set time will not always work, or be efficient. This is a sloppy solution in my opinion and I would like to avoid it.
Does anyone know of a way, I can access an object, by the Task name, or maybe window name, and set it to a workbook object? Or perhaps to save it, if I could get the document saved to any drive and closed, then I would be able to open it easily.
This is for work, and so I will provide what information I can, but it may be limited. Any help or suggestions would be appreciated.
Eric
The problem comes in when I download the query results from our web application. The results are downloaded into an excel based document, but the document does not register under the excel.applications. When I review the path and name of the object after it is downloaded they are both HTML references. I have looked for a temporary path to the file but I can't find it actually being saved anywhere.
If it were a simple excel document, I could locate it by name, path or I could easily loop through the Excel.Application object and find it, or use the GetObject command. But none of those work:
'With this the file is never found
For each w in Excel.Application.Workbooks
If w.Name = ExpectedFileName then
Set wbook = w
Exit For
endif
Next w
I have tried using the TASKS collection in word, and I can locate it with a simple loop, but I can't do anything useful once I have found it. I have tried setting a workbook variable to the task, but that always results in the variable being set to nothing:
'Results in wbook being set to nothing
For each T in Tasks
If T.visible = True and T.Name = ExpectedFileName then
Set wbook = T
Exit For
EndIf
Next T
I have considered going old school and using a send keys string with pauses in the appropriate locations to allow the file to be saved. The problem I have with this is that there are many different reports, many different sizes, so waiting a set time will not always work, or be efficient. This is a sloppy solution in my opinion and I would like to avoid it.
Does anyone know of a way, I can access an object, by the Task name, or maybe window name, and set it to a workbook object? Or perhaps to save it, if I could get the document saved to any drive and closed, then I would be able to open it easily.
This is for work, and so I will provide what information I can, but it may be limited. Any help or suggestions would be appreciated.
Eric