• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

vba macro

r@1234

Member
I have two files opened
macro.xlsm
1.xlsx
i need a macro that will close 1.xlsx
Both file are located in different path
So plz help me for the same
 
The line
Workbooks("1.xlsx").Close
will close the file if it is open

if you don't want to save changes use
Workbooks("1.xlsx").Close SaveChanges:=False
 
vletm thnx alot that u have remembered this question
Actually let me explain u the exact situation so u can understand what is happening
I am using software to download the file, once the file is downloaded(automatically file is opened,I am not opening the file)
& when i use the macro to close the file it is not working (the file is not closed by a vba macro)
I don't know why it is happening

(i am closing the file manually this is the one solution that i have and i am using the same solution, But i got a vba macro that can close that file then it will be a Great Help)
 
Code:
Sub macro()
Workbooks("1.xls").Close
End Sub


I used this code & i am getting error(plz see the attachment)

Condition1-(When i download the file & file opened automatically & run this macro then i am getting error which i have attached )
Condition2-(When i download the file & file opened automatically &then i closed that file manually & then i reopen the file & i run this macro then it is working perfectly )


I want the Macro that work for condition 1
 

Attachments

  • Capture.PNG
    Capture.PNG
    4 KB · Views: 11
As this message just clearly means the workbook is not opened so maybe a typo in your code,​
check by code at least each opened workbook name …​
 
No Problem I have consulted the same to many professional but i think its not the macro issue that software issue will be there no issues Problem Solved
I will do this manually or by some anyother way but by vba it is not possible i think so Thnx Alot
 
It's always possible but it requires a smart enough explanation as this is very not a mind readers forum​
even if we have an idea of your issue, the solution is yet under your eyes, well read​
and well observe what happens on your Excel side … (just checking the opened workbooks where the macro workbook is opened )
Without forgetting any forum rules like here again the poor title very not relevant ! …​
 
Marc L
As You wrote with #7 reply and
after that reread #6 reply and
go back to #1 reply
then there no need to have many professional to notice something which do not match!
Maybe that is same effect as if more than one cook in the kitchen!
 
Yes, like the father asking his son to come back with a fresh beer, the son answering there is no beer in the fridge,​
the father arguing he well knows there are some beers in the fridge but in fact as they have two fridges,​
beers are just not located in the fridge where the son stands …​
 
No Problem I have consulted the same to many professional but i think its not the macro issue that software issue will be there no issues Problem Solved
I will do this manually or by some anyother way but by vba it is not possible i think so Thnx Alot

In your first pouint it is:
Workbooks("1.xlsx").Close

now it is
Workbooks("1.xls").Close

They are not the same filename
 
Actual file name of 1.xlsx is 1.xls , i tested that macro on 1.xls
No issue the code is working with all the files but not with that file in that situation
Ur macro is perfect no doubt in it
Problem Solved
 
r@1234
If You explain something and that something is else than You have explained.
Something like - how much 2-1=? and You formula is 2+1=?
How would You get solution, which match with something else?
Take care.
 
Its not about match vletm Sir
the code is working for all files but not on that file in that situation
Normally if we downloaf file it is saved(it never be an opened state)

But when i download that file it opens up as soon as download completed
 
O B V I O U S L Y :​
Leonardo once you are facing one workbook or another - whatever - check the list of opened workbooks​
then you must understand what you misobserved, maybe the same story than for fridges & beers !​
Solution belongs to well readers …​
 
Code:
Sub Check_If_Workbook_Open()
Dim wbk As Workbook
For Each wbk In Workbooks
If wbk.Name = "1.xls" Then
MsgBox "workbook is open"
End If
Next
End Sub



I used this code to check file it is opened or not then what happens is mentioned below

Case 1)I opened the file manually and then i ran the code then i got this msg "workbook is open"
Case 2)when i download the file,it opens up automatically & when i try to run the same macro then i am not getting any msg


in case2 i have not done anything manual (i have not opened the file , it opens up automatically when download completed) & the code is unable to detect wheather its opened or not

So we have to think differently to solve the same


If u want to help me then plz let me know the website( forum ) where windows programmers are present
I will get some code by them that close all the files of excel bcoz vba macro is unable to detect the same
 
is there any vba macro that completely close all the excel file or all excel process
I am not talking about closing of that file
I am talking about completely stop excel to work
 
Case 2)when i download the file,it opens up automatically & when i try to run the same macro then i am not getting any msg
Finally Leonardo / shinshan / … you start at least to read answers, not too early but hope it sounds better !​
So if your procedure does not display any message, what do you think that means ?​
Just well reading post #11 & 16 you should see the light !​
Excel can display a list of opened workbooks, see in its obvious Display menu​
and compare the list when your are facing each workbook …​
… or obviously again just taking a glance to the Windows Tasks Manager …​
 
I saw that bro but plz provide me solution for the same, I am not a professional one
u r giving me a hint but i am unable to catch the same
 
You saw what ?! Just answer to question as I can go further only if I'm sure you understand a step point …​
As you are here a 'professional asker' not respecting forum rules with several log in nicknames !​
 
Bro who told u that i am not respecting forum rules
I have a great respect for the same , and from last 3-4 months i am following all terms and condition of forum,
using only one account
 
bro u told about father and his son & two fridge & beer
I need that in a macro bro
I think u understood what i mean to say so its my request plz let me know clearly what i have to do
& if u provide me the macro for the same then it will be a great help for me
 
Maybe the next time you create a thread within this forum - in fact whatever the forum ! - with​
the initial post respecting the rules you should have a solution in the next post …​
To demonstrate how this thread does not respect the rules,​
the reason why you must follow mine so we must restart with two easy kid level questions.​
First one : what is the name of this forum ? (help 4 Dumb : top page at the right of the Home line)
 
Back
Top