|
-
Jun 25th, 2008, 11:14 AM
#1
Thread Starter
Hyperactive Member
Excel VBA > SaveAs >> over write current file
I have been using the below code and it seems to work very well. However, It currently prompts me to over write the file that is currently there. (same file name)
Is there a way I can do this automatically in the save as step at the bottom?
Code:
ActiveWorkbook.SaveAs Filename:=_
"C:\Users\Owner\Documents\_DENSO QRE\SKPI PARTS RETURN\all_namc_skpi_download.xls"_
Code:
Public Sub SKPIUPDATE()
Dim QPR
Dim lnk
Dim frm
Dim start
Dim fin
Dim drp1
Dim drp2
Dim src1
Dim NAMC As Integer
' This macro will automatically open and download the TMMK-VEH daily scrap
'and store the file in the same directory
Set QPR = CreateObject("InternetExplorer.application")
QPR.Visible = True
QPR.navigate "https://www.portal.toyotasupplier.com/wps/myportal/"
Do While QPR.Busy: DoEvents: Loop
Do While QPR.readyState <> 4: DoEvents: Loop
With QPR.document.forms("Login")
.User.Value = "*******"
.Password.Value = "*******"
.submit
End With
Application.Wait Now + TimeSerial(0, 0, 11)
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/")
Application.Wait Now + TimeSerial(0, 1, 60)
If myNAMC = "TMMK-VEH" Then
NAMC = 4
ElseIf myNAMC = "TMMK-PWT" Then
NAMC = 3
ElseIf myNAMC = "TMMC" Then
NAMC = 5
ElseIf myNAMC = "TMMTX" Then
NAMC = 6
ElseIf myNAMC = "TABC" Then
NAMC = 7
ElseIf myNAMC = "NUMMI" Then
NAMC = 8
ElseIf myNAMC = "TMMI" Then
NAMC = 9
ElseIf myNAMC = "TMMTX" Then
NAMC = 6
ElseIf myNAMC = "TMMBC" Then
NAMC = 10
ElseIf myNAMC = "TMMAL" Then
NAMC = 11
ElseIf myNAMC = "TMMNK" Then
NAMC = 12
End If
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
Do While QPR.Busy: DoEvents: Loop
Do While QPR.readyState <> 4: DoEvents: Loop
lnk.Click
Do While QPR.Busy: DoEvents: Loop
Do While QPR.readyState <> 4: DoEvents: Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/SkpiGatewayServlet?jadeAction=NCPARTS_SEARCH")
Do While QPR.Busy: DoEvents: Loop
Do While QPR.readyState <> 4: DoEvents: Loop
Set frm = QPR.document.forms("form1")
Set dwn = QPR.document.forms("page")
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 src1 = frm.all("Submit")
src1.Click
Do While QPR.Busy: DoEvents: Loop
Do While QPR.readyState <> 4: DoEvents: Loop
QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/DownloadNCPartListServlet")
Application.Wait Now + TimeSerial(0, 1, 0)
Windows("DownloadNCPartListServlet").Activate
ActiveWorkbook.SaveAs Filename:=_
"C:\Users\Owner\Documents\_DENSO QRE\SKPI PARTS RETURN\all_namc_skpi_download.xls"_
ActiveWorkbook.Close
QPR.navigate ("https://www.portal.toyotasupplier.com/public/pr_logout.htm")
Windows("SKPI 2008.xls").WindowState = xlMaximized
-
Jun 25th, 2008, 04:20 PM
#2
Re: Excel VBA > SaveAs >> over write current file
Code:
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs (etc.)
Application.DisplayAlerts = True
Hope this helps...
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
-
Jun 25th, 2008, 04:27 PM
#3
Re: Excel VBA > SaveAs >> over write current file
 Originally Posted by koolsid
Code:
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs (etc.)
Application.DisplayAlerts = True
Hope this helps...
That shouldnt work as turning off display alerts forces the default selection of the warning dialog for overwritting which is "No".
Why cant you use the .Save instead?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 25th, 2008, 04:29 PM
#4
Re: Excel VBA > SaveAs >> over write current file
Hi Rob I have tried it and it works...
when display alerts is off, it won't ask you. it will simply owerwrite the file...
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
-
Jun 25th, 2008, 04:32 PM
#5
Re: Excel VBA > SaveAs >> over write current file
Are you sure 
http://msdn.microsoft.com/en-us/library/aa205032.aspx
When using the SaveAs method for workbooks to overwrite an existing file, the 'Overwrite' alert has a default of 'No', while the 'Yes' response is selected by Excel when the DisplayAlerts property is set equal to True.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 25th, 2008, 04:42 PM
#6
Re: Excel VBA > SaveAs >> over write current file
 Originally Posted by RobDog888
Hi Rob Can I sue the website 
I just tried it again and it works First I tried it without the display alerts and it prompted me. Then I tried with the following code and it didn't prompt me... Try it out yourself...
Code:
Private Sub CommandButton1_Click()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"P:\1-1\Book11.xls"
Application.DisplayAlerts = True
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
-
Jun 25th, 2008, 07:31 PM
#7
Re: Excel VBA > SaveAs >> over write current file
 Originally Posted by Bill Gates
When using the SaveAs method for workbooks to overwrite an existing file, the 'Overwrite' alert has a default of 'No', while the 'Yes' response is selected by Excel when the DisplayAlerts property is set equal to True.
Hi Bill, The word "True" should be read "False".
***
It may be OK to use Application.DisplayAlerts = False.
But what happens if the the file to be overwritten is being in used?
In that case, a run-time error message will be display because the file cannot be overwritten. This error need to be handled.
-
Jun 26th, 2008, 06:38 AM
#8
Thread Starter
Hyperactive Member
Re: Excel VBA > SaveAs >> over write current file
It worked great for me.
But as I understand it. This will only work for display's from Excel and not one from Windows.
Example:
I get a Windows dialog box when I download a file into excel from a Website that ask me if I want to open or save the file. I don't think this will work for that one.
Thanks for the help.
-
Jun 26th, 2008, 07:30 AM
#9
Re: Excel VBA > SaveAs >> over write current file
I get a Windows dialog box when I download a file into excel from a Website that ask me if I want to open or save the file. I don't think this will work for that one.
no it won't work for that one
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
-
Jun 30th, 2008, 05:28 AM
#10
New Member
Re: Excel VBA > SaveAs >> over write current file
thanks, works for me.
only had to trawl about 8 google pages to find it.
-
Jul 7th, 2008, 09:23 PM
#11
Re: Excel VBA > SaveAs >> over write current file
 Originally Posted by ggodwin
It worked great for me.
But as I understand it. This will only work for display's from Excel and not one from Windows.
Example:
I get a Windows dialog box when I download a file into excel from a Website that ask me if I want to open or save the file. I don't think this will work for that one.
Thanks for the help.
Probably not as macros are usually disabled by default with a browser/IE
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 8th, 2008, 11:31 AM
#12
Thread Starter
Hyperactive Member
RESOLVED » Re: Excel VBA > SaveAs >> over write current file
I had forgotten about this thread...
But yes that command fixed the issue. On the Windows dialogue box. Once I checked the box it has never come back.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|