Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

workbooks.add

  Asked By: Grant    Date: Sep 17    Category: MS Office    Views: 930
  

I've the following sub in a class module

Sub sAddNewWorkbook()
Debug.Print "Full File Name:", Me.fFullName
With Workbooks
.Add.SaveAs Me.fFullName
End With
End Sub

I can not see anything wrong with this sub. However it does not
produce a new workbook everytime it's called. Although everytime the
full filename is valid, as tested with the debug.print statement.
I've tried several variations on the specific syntax with the same
result. I suppose it most be some strange memory problem or something,
or at least something not related to this specific sub.
Anyone got any idea where to look for the problem?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Ethan Evans     Answered On: Sep 17

I wonder about your Me.fFullName - does it return a full, absolute path (eg,
"C:\path1\filename.xls") or a relative one ("filename.xls")? If it's
relative, the question is where is it saving it.



Do you get an error of some kind? Can you step through the code and see
what's happening? When it hits the SaveAs line, you should be able to tell
if you flip back to the Workbook and see if it is now saved or not and with
what name. And if you then try File/SaveAs you should be able to tell in
which folder it's saved too.

 
Answer #2    Answered By: Komal Mohammad     Answered On: Sep 17

The me.ffullname does provide a full  path in every instance.
I've also tried seperating the saving of the new workbook  from the
creation. When i run the code until the saving I notice that in the
succesfull runs a workbook "book2" is created, in the unsuccessfull
runs nothing is created and subsequently ofcourse nothing is saved.

 
Answer #3    Answered By: Chau Tran     Answered On: Sep 17

What I would do is step through the code in the debugger and see if I could
catch it failing to see under what conditions it fails. It's so hard to
track down bugs that only happen sometimes, so I always try to figure out
what the conditions are that cause the failure. I would also break out each
action into a separate line of code so you might be able to narrow it down
even further. In this case, I would split up the .Add from the .SaveAs and
see if that helps you at all.

 
Didn't find what you were looking for? Find more on workbooks.add Or get search suggestion and latest updates.




Tagged: