Close.xls file by a macro
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Close.xls file by a macro
I have a software & when I download a file from it 1.xls then it's open automatically (I am not opening the file manually by me, it opens up automatically when it get's downloaded)
So the problem is, I have tried many macros to close that file but that file is not closed by any macros, that I get from many coders
If I use that macros to close the file then the file should be opened by me manually then only all the macros work
So for that there will be a different macro
Or this problem is not solvable by vba?
If it's not solvable by vba then may I know the alternative option to close any excel file
So the problem is, I have tried many macros to close that file but that file is not closed by any macros, that I get from many coders
If I use that macros to close the file then the file should be opened by me manually then only all the macros work
So for that there will be a different macro
Or this problem is not solvable by vba?
If it's not solvable by vba then may I know the alternative option to close any excel file
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Close.xls file by a macro
Does this work for you?
Code: Select all
Sub CloseWorkbook()
Dim wb As Object
On Error Resume Next
Set wb = GetObject("1.xls")
If Not wb Is Nothing Then
wb.Close SaveChanges:=False
End If
End Sub
Best wishes,
Hans
Hans
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Code: Select all
Sub CloseWorkbook()
Dim wb As Object
On Error Resume Next
Set wb = GetObject("1.xls")
If Not wb Is Nothing Then
wb.Close SaveChanges:=False
End If
End Sub
I use this & file is not close by the macro
& i use the below
Code: Select all
Sub CloseWorkbook()
Dim wb As Object
On Error Resume Next
Set wb = GetObject("C:\Users\**I've been banned**\Desktop\1.xls")
If Not wb Is Nothing Then
wb.Close SaveChanges:=False
End If
End Sub
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Close.xls file by a macro
That's a pity. If closing normally doesn't work and this macro doesn't either, I'm out of ideas.
Best wishes,
Hans
Hans
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Ok HansV Sir
-
- 2StarLounger
- Posts: 102
- Joined: 04 Feb 2010, 22:44
- Location: Melbourne Australia
Re: Close.xls file by a macro
Is this code running in Excel or something else?
Can you iterate through the open workbooks to see if any have that name.
Can you iterate through the open workbooks to see if any have that name.
Code: Select all
Sub CloseWorkbook()
Dim aWB As Workbook
For Each aWB In Application.Workbooks
If aWB.Name = "1.xlsx" Then
aWB.Close SaveChanges:=False
Exit For
End If
Next aWB
End Sub
Andrew Lockton
Melbourne Australia
Melbourne Australia
-
- Administrator
- Posts: 12612
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Close.xls file by a macro
I wonder if the problematic workbook is open in a different instance of Excel to the workbook where the Macro is running
StuartR
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Code: Select all
Sub CloseWorkbook()
Dim aWB As Workbook
For Each aWB In Application.Workbooks
If aWB.Name = "C:\Users\**I've been banned**\Desktop\1.xls" Then
aWB.Close SaveChanges:=False
Exit For
End If
Next aWB
End Sub
Code: Select all
Sub CloseWorkbook()
Dim aWB As Workbook
For Each aWB In Application.Workbooks
If aWB.Name = "1.xls" Then
aWB.Close SaveChanges:=False
Exit For
End If
Next aWB
End Sub
I have used both the macros & it doesn' close that file Sir
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
I wonder if the problematic workbook is open in a different instance of Excel to the workbook where the Macro is running
Ok so what will be the macro u suggest StuartR Sir?
Ok so what will be the macro u suggest StuartR Sir?
-
- Administrator
- Posts: 12612
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Close.xls file by a macro
I'm not that clever!
How is the problem workbook being opened, is it in a Macro or what? You say it is downloaded, but that doesn't tell us who or what is opening the workbook.
StuartR
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Yes u can see
what is the problem
I am uploading the .xls file here just download that .xls file from this post & once u download the file, then it will open automatically in ur pc & try to close that file by a macro which u have given it to me (put the macro to macro.xlsm & run the macro ) & u will notice that file which is opened is not closing by the macro
what is the problem
I am uploading the .xls file here just download that .xls file from this post & once u download the file, then it will open automatically in ur pc & try to close that file by a macro which u have given it to me (put the macro to macro.xlsm & run the macro ) & u will notice that file which is opened is not closing by the macro
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Close.xls file by a macro
It doesn't work that way - apparently the workbook is automatically opened when you download it from the original website. It doesn't open automatically when I download it from this thread to my hard disk. I have to open it myself (and then, any of the macros that you tried should close it)
Best wishes,
Hans
Hans
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
So HansV Sir u mean to say that u downloaded this file & its not opened automatically in ur pc ?
U have opened it manually ?
U have opened it manually ?
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Close.xls file by a macro
Yes, indeed. The workbook did not open automatically when I downloaded it.
Best wishes,
Hans
Hans
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Ok That's Great, So we found the problem
In my pc this file is opened automatically
So plz suggest me the solution to stop the file opening automatically after downloading
Plz provide me which settings i have to change in excel
I am using Excel 2013
In my pc this file is opened automatically
So plz suggest me the solution to stop the file opening automatically after downloading
Plz provide me which settings i have to change in excel
I am using Excel 2013
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Close.xls file by a macro
Which browser are you using when you download the workbook?
Best wishes,
Hans
Hans
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Google chrome
When I download .xlsx file then it is downloaded but It never opens automatically
But only .XLS files opens up automatically
One more thing I would like to inform u, why we are playing with browser , Excel doesn't have setting to stop automatically opening of files?
(The reason why I am asking this question is bcoz If we can fix the Problem from Excel settings it will be very very beneficial for me & If we are fixing the issue by targetting browser setting then it will only work for browser
When I download .xlsx file then it is downloaded but It never opens automatically
But only .XLS files opens up automatically
One more thing I would like to inform u, why we are playing with browser , Excel doesn't have setting to stop automatically opening of files?
(The reason why I am asking this question is bcoz If we can fix the Problem from Excel settings it will be very very beneficial for me & If we are fixing the issue by targetting browser setting then it will only work for browser
-
- Administrator
- Posts: 78532
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Close.xls file by a macro
As far as I can tell, it must be a browser setting, not an Excel setting.
Download a .xls file from Chrome.
The filename should be displayed in the download bar at the bottom of the Chrome window.
Click the small arrow to the right of the filename.
You will probably see a check mark next to 'Always open files of this type'.
Click on this option to remove the check mark.
.xls files shouldn't be opened automatically anymore from now on.
Download a .xls file from Chrome.
The filename should be displayed in the download bar at the bottom of the Chrome window.
Click the small arrow to the right of the filename.
You will probably see a check mark next to 'Always open files of this type'.
Click on this option to remove the check mark.
.xls files shouldn't be opened automatically anymore from now on.
Best wishes,
Hans
Hans
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
Ok No Problem
Thnx for the info
Thnx for the info
-
- Banned
- Posts: 253
- Joined: 22 Apr 2020, 17:24
Re: Close.xls file by a macro
https://www.excelforum.com/excel-progra ... rompt.html
taskkill /F /IM EXCEL.EXE
this line i put in cmd &I run that, then it closes all the excel file including that file also sir(This is also a Great Option for me )
But i found one more line to put in cmd that will close the excel file (it wil not close all the excel file, it will only close a specified excel file)
TASKKILL /FI "WINDOWTITLE eq Microsoft Excel - Book3.xls"
I need clarity on this line
what is this "WINDOWTITLE eq Microsoft Excel - Book3.xls"
plz guide HansV Sir & plz make this line workable TASKKILL /FI "WINDOWTITLE eq Microsoft Excel - Book3.xls"
taskkill /F /IM EXCEL.EXE
this line i put in cmd &I run that, then it closes all the excel file including that file also sir(This is also a Great Option for me )
But i found one more line to put in cmd that will close the excel file (it wil not close all the excel file, it will only close a specified excel file)
TASKKILL /FI "WINDOWTITLE eq Microsoft Excel - Book3.xls"
I need clarity on this line
what is this "WINDOWTITLE eq Microsoft Excel - Book3.xls"
plz guide HansV Sir & plz make this line workable TASKKILL /FI "WINDOWTITLE eq Microsoft Excel - Book3.xls"