Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
I am not having a problem with the download. I am able to get the data.
I just need to tell the application to save it and give it the file name details that I need.
Option Compare Database
Option Explicit
Public Function SKPIUPDATE()
Dim QPR As Object
Dim lnk As Object
Dim TimeOut As String
Dim frm As Object
Dim Start As Object
Dim Finish As Object
Dim drp2 As Object
Dim drp1 As Object
Dim src1 As Object
Dim p1 As Variant
Dim objExc As Object
Dim objWB As Object
Set QPR = CreateObject("InternetExplorer.application")
QPR.Visible = True
QPR.navigate "https://www.portal.toyotasupplier.com/wps/myportal/"
TimeOut = Now + TimeValue("00:00:20") '-- wait maximum of 20 seconds
Do While QPR.Busy Or QPR.readyState <> 4
DoEvents
If Now > TimeOut Then
MsgBox "Time Out before Login"
Exit Function
End If
Loop
With QPR.Document.Forms("Login")
.User.Value = "***********"
.Password.Value = "*******"
.submit
End With
TimeOut = Now + TimeValue("00:00:40") '-- wait maximum of 10 seconds
Do While QPR.Busy Or QPR.readyState <> 4
DoEvents
If Now > TimeOut Then
MsgBox "Time Out after Login"
Exit Function
End If
Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/")
TimeOut = Now + TimeValue("00:00:05") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
TimeOut = Now + TimeValue("00:00:50") '-- wait maximum of 10 seconds
Do While QPR.Busy Or QPR.readyState <> 4
DoEvents
If Now > TimeOut Then
MsgBox "Did not navigate to SKPI application"
Exit Function
End If
Loop
Set lnk = QPR.Document.Links(3) ' 3=TMMK-VEH,4=TMMK-PWT,5=TMMC,6=TMMTX,7=TABC,8=NUMMI,9=TMMI,10=TMMBC,11=TMMAL,12=TMMNK
lnk.Click
TimeOut = Now + TimeValue("00:00:20") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/SkpiGatewayServlet?jadeAction=NCPARTS_SEARCH")
TimeOut = Now + TimeValue("00:00:05") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
Set frm = QPR.Document.Forms("form1")
Set Start = frm.all("SKPI_SEARCH_START_DATE_KEY")
Start.Value = "01/01/" & Year(Now)
Set Finish = frm.all("SKPI_SEARCH_END_DATE_KEY")
Finish.Value = Format(Now - 1, "mm/dd/yyyy")
Set drp2 = frm.all("SKPI_SEARCH_NC_TYPE_KEY")
drp2.Item(1).Selected = True
Set drp1 = frm.all("SKPI_SEARCH_NAMC_KEY")
drp1.Item(p1).Selected = True
Set src1 = frm.all("Submit")
src1.Click
TimeOut = Now + TimeValue("00:00:05") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/DownloadNCPartListServlet") ' this download the Excel file DownloadNCPartListServlet.xls
TimeOut = Now + TimeValue("00:01:00") '-- wait 1 minute for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
Set objExc = CreateObject("Excel.Application")
objExc.Visible = True 'comment out if not required
Set objWB = objExc.("Download.xls")
objWB.SaveAs "C:SKPIUPDATE.xls"
'QPR.navigate ("https://www.portal.toyotasupplier.com/public/pr_logout.htm")
End Function
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Sub DownloadFileFromWeb()
On Error GoTo err_1
'Insert the file link below
Const strUrl As String = "http://www.koolsid.com/Myfile.xls" 'example link
Dim strSavePath As String
Dim returnValue As Long
'Path to save the file
strSavePath = "c:/temp"
returnValue = URLDownloadToFile(0, strUrl, strSavePath, 0, 0)
Err_Exit:
Exit Sub
err_1:
MsgBox Err.Description
Resume Err_Exit
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
objExc.Visible = True 'comment out if not required
Set objWB = objExc.("Download.xls")
objWB.SaveAs "C:SKPIUPDATE.xls"
Use this
On Error GoTo err_1
'Insert the file link below
Const strUrl As String = "http://www.koolsid.com/Myfile.xls" 'example link
Dim strSavePath As String
Dim returnValue As Long
'Path to save the file
strSavePath = "c:/temp"
returnValue = URLDownloadToFile(0, strUrl, strSavePath, 0, 0)
Err_Exit:
Exit Sub
err_1:
MsgBox Err.Description
Resume Err_Exit
This
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
will go after
Option Explicit
in your code.
Regarding the errorhandling
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Err_Exit:
'line above is a label - if you are using goto on the error or elsewhere you should know this
exit function
'equivalent of exit sub - but for a function
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Option Compare Database
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function SKPIUPDATE()
Dim QPR As Object
Dim lnk As Object
Dim TimeOut As String
Dim frm As Object
Dim Start As Object
Dim Finish As Object
Dim drp2 As Object
Dim drp1 As Object
Dim src1 As Object
Dim p1 As Variant
Dim objWB As Object
Dim objExc As Object
Set QPR = CreateObject("InternetExplorer.application")
QPR.Visible = True
QPR.navigate "https://www.portal.toyotasupplier.com/wps/myportal/"
TimeOut = Now + TimeValue("00:00:20") '-- wait maximum of 20 seconds
Do While QPR.Busy Or QPR.readyState <> 4
DoEvents
If Now > TimeOut Then
MsgBox "Time Out before Login"
Exit Function
End If
Loop
With QPR.Document.Forms("Login")
.User.Value = "********"
.Password.Value = "********"
.submit
End With
TimeOut = Now + TimeValue("00:00:40") '-- wait maximum of 10 seconds
Do While QPR.Busy Or QPR.readyState <> 4
DoEvents
If Now > TimeOut Then
MsgBox "Time Out after Login"
Exit Function
End If
Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/")
TimeOut = Now + TimeValue("00:00:05") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
TimeOut = Now + TimeValue("00:00:50") '-- wait maximum of 10 seconds
Do While QPR.Busy Or QPR.readyState <> 4
DoEvents
If Now > TimeOut Then
MsgBox "Did not navigate to SKPI application"
Exit Function
End If
Loop
Set lnk = QPR.Document.Links(3) ' 3=TMMK-VEH,4=TMMK-PWT,5=TMMC,6=TMMTX,7=TABC,8=NUMMI,9=TMMI,10=TMMBC,11=TMMAL,12=TMMNK
lnk.Click
TimeOut = Now + TimeValue("00:00:20") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/SkpiGatewayServlet?jadeAction=NCPARTS_SEARCH")
TimeOut = Now + TimeValue("00:00:05") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
Set frm = QPR.Document.Forms("form1")
Set Start = frm.all("SKPI_SEARCH_START_DATE_KEY")
Start.Value = "01/01/" & Year(Now)
Set Finish = frm.all("SKPI_SEARCH_END_DATE_KEY")
Finish.Value = Format(Now - 1, "mm/dd/yyyy")
Set drp2 = frm.all("SKPI_SEARCH_NC_TYPE_KEY")
drp2.Item(1).Selected = True
Set drp1 = frm.all("SKPI_SEARCH_NAMC_KEY")
drp1.Item(p1).Selected = True
Set src1 = frm.all("Submit")
src1.Click
TimeOut = Now + TimeValue("00:00:05") '-- wait 1 second for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/DownloadNCPartListServlet")
TimeOut = Now + TimeValue("00:01:00") '-- wait 1 minute for above navigation to take effect
Do While Now < TimeOut
DoEvents
Loop
'Insert the file link below
Const strUrl As String = "https://www.portal.toyotasupplier.com/skpi/DownloadNCPartListServlet" 'example link
Dim strSavePath As String
Dim returnValue As Long
'Path to save the file
strSavePath = "C:\Documents and Settings\dsggodwin\My Documents\_DENSO QRE"
returnValue = URLDownloadToFile(0, strUrl, strSavePath, 0, 0)
err_1:
MsgBox Err.Description
Resume Err_Exit
Err_Exit:
QPR.navigate ("https://www.portal.toyotasupplier.com/public/pr_logout.htm")
End Function
Still not saving on my end regardless the method. Either adding the delay or commenting out the logout request..
I have no idea what could be wrong.? What is the file name and were would it save it? I see the path? but maybe I am missing it?
If/when a user navigates to this location the user always receives a prompt that as what they want to do. Open or save the file This is a prompt that you can "un check" to eliminate in the future. For me it is set to open with out the prompt.
Could that be a difference? If you navigate there manually will you get the prompt?
If/when a user navigates to this location the user always receives a prompt that as what they want to do. Open or save the file This is a prompt that you can "un check" to eliminate in the future. For me it is set to open with out the prompt.
Are you at least getting the prompt to open the file or to save it via code?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
If the checkbox is checked then it will ask you to either open the file or save the file. If the checkbox is not checked then it will download the file and open the excel file in the same browser. At least that is what has happened with me...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Ok. Please confirm.
Did the downloaded excel file open in the explorer or in excel? If this code requires it to be opened in the IE Browser I can fix that on mine.
Did you get the file to save? If yes, what is the file name and location?
Last edited by ggodwin; Aug 27th, 2008 at 01:17 PM.
Did the downloaded excel file open in the explorer or in excel?
It opened in explorer when the check box was not checked
Did you get the file to save? If yes, what is the file name and location?
yes, I got the file to save when there was a check on the checkbox. Give me some time for the file name as I will have to mail the code to one of my friends pc as I don't have access to net (except vbforums on this pc...
Edit:
okay Here is a step by step screenshot when the checkbox is checked
Last edited by Siddharth Rout; Aug 27th, 2008 at 01:44 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero