Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Breaking a UserForm


I'm in the process of trying to trash a userform before turning it into
a add-in.

Originally, part of my code held:


Code:
--------------------
Select Case rngNetwork
Case 1
Set wrkbkUrl = Workbooks.Open(Filename:="P:\VBA training\Excel templates for Network stats\1 Network.xls")
Sheets(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", "TempAnalysis", "Yearly summary")).Select
Cells.Replace What:="1st Network", Replacement:=strNetwork1, LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False

Sheets("Jan").Select
Range("C3").Select

savewrkbkname = Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveAs Filename:=savewrkbkname
--------------------


which did the job but one of the senarios I created was:

What if the user cancelled the save before the save was completed?
This highlighted a bug that saved the '1 Network.xls' as 'False'
instead of cancelling the save.

In order to try and remedy this I changed the code to:


Code:
--------------------
If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")

Else: ActiveWorkbook.Close
End If
--------------------


However, this gave a 'Type Mismatch' error

Does anyone have an insight to what's going wrong please?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=507586

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Breaking a UserForm

Hi Daminc,

Try:

Dim FName As Variant

FName = Application.GetSaveAsFilename _
(InitialFileName:=wrkbkname, _
fileFilter:="Excel Files (*.xls), *.xls")

If FName = False Then
ActiveWorkbook.Close SaveChanges:=False
Else
ActiveWorkbook.SaveAs FName
End If


---
Regards,
Norman


"Daminc" wrote in
message ...

I'm in the process of trying to trash a userform before turning it into
a add-in.

Originally, part of my code held:


Code:
--------------------
Select Case rngNetwork
Case 1
Set wrkbkUrl = Workbooks.Open(Filename:="P:\VBA training\Excel templates
for Network stats\1 Network.xls")
Sheets(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sept", "Oct", "Nov", "Dec", "TempAnalysis", "Yearly summary")).Select
Cells.Replace What:="1st Network", Replacement:=strNetwork1,
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False

Sheets("Jan").Select
Range("C3").Select

savewrkbkname = Application.GetSaveAsFilename(wrkbkname,
fileFilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveAs Filename:=savewrkbkname
--------------------


which did the job but one of the senarios I created was:

What if the user cancelled the save before the save was completed?
This highlighted a bug that saved the '1 Network.xls' as 'False'
instead of cancelling the save.

In order to try and remedy this I changed the code to:


Code:
--------------------
If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files
(*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname,
fileFilter:="Excel Files (*.xls), *.xls")

Else: ActiveWorkbook.Close
End If
--------------------


However, this gave a 'Type Mismatch' error

Does anyone have an insight to what's going wrong please?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:
http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=507586



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Breaking a UserForm

it's ridiculous assumption, but if i input false in filename box,
i think it'll make a file named as false.xls.

"Norman Jones" wrote in message
...
Hi Daminc,

Try:

Dim FName As Variant

FName = Application.GetSaveAsFilename _
(InitialFileName:=wrkbkname, _
fileFilter:="Excel Files (*.xls), *.xls")

If FName = False Then
ActiveWorkbook.Close SaveChanges:=False
Else
ActiveWorkbook.SaveAs FName
End If


---
Regards,
Norman


"Daminc" wrote in
message ...

I'm in the process of trying to trash a userform before turning it into
a add-in.

Originally, part of my code held:


Code:
--------------------
Select Case rngNetwork
Case 1
Set wrkbkUrl = Workbooks.Open(Filename:="P:\VBA training\Excel templates
for Network stats\1 Network.xls")
Sheets(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sept", "Oct", "Nov", "Dec", "TempAnalysis", "Yearly summary")).Select
Cells.Replace What:="1st Network", Replacement:=strNetwork1,
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False

Sheets("Jan").Select
Range("C3").Select

savewrkbkname = Application.GetSaveAsFilename(wrkbkname,
fileFilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveAs Filename:=savewrkbkname
--------------------


which did the job but one of the senarios I created was:

What if the user cancelled the save before the save was completed?
This highlighted a bug that saved the '1 Network.xls' as 'False'
instead of cancelling the save.

In order to try and remedy this I changed the code to:


Code:
--------------------
If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files
(*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname,
fileFilter:="Excel Files (*.xls), *.xls")

Else: ActiveWorkbook.Close
End If
--------------------


However, this gave a 'Type Mismatch' error

Does anyone have an insight to what's going wrong please?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:
http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=507586




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Breaking a UserForm

Hi Kounoike,

it's ridiculous assumption, but if i input false in filename box,
i think it'll make a file named as false.xls.


There is a diiference between the boolean False and the string "False".

If desired, the string "False" is a perfectly acceptable name for a
workbook.

The expression:

If FName = False Then


False is the boolean value; it is not a string value.

---
Regards,
Norman


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Breaking a UserForm

"Norman Jones" wrote in message
...
Hi Kounoike,

There is a diiference between the boolean False and the string "False".

If desired, the string "False" is a perfectly acceptable name for a
workbook.

The expression:

If FName = False Then


False is the boolean value; it is not a string value.


Thank you for your reply, Norman and Sorry for misread your code.
your code can't make a file e.g false.xls

set aside above, i also think as you say at first.
but i try something like this.

s = "false"
If s = False Then
msgbox "equal"
Else
msgbox "not equal"
Endif

it returns equal.
Am i missing something?

Thanks

keizi



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Breaking a UserForm


kounoike skrev:


s = "false"
If s = False Then
msgbox "equal"
Else
msgbox "not equal"
Endif

it returns equal.
Am i missing something?

Thanks

keizi


In this situation Excel will be able to translate between the string
"false" and the boolean value False, which might be a good thing (or
not, I vote for 'not').

But if you get another string (for example a file name) into the above
variable, it will cast the error the OP got, Type mismatch.

Is it clearer now?

/impslayer, aka Birger Johansson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Breaking a UserForm


Hi Norman, before I try that (there is a lot of code in total and you
suggestion would require a lot of changes) is there any reason that yo
can see that would result in my code bringing up a Type Mismatch error

--
Damin
-----------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...fo&userid=2707
View this thread: http://www.excelforum.com/showthread.php?threadid=50758

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Breaking a UserForm

Hi Daminic,

Your latest code worked for me.

How have you dimmed your variables?


---
Regards,
Norman



"Daminc" wrote in
message ...

Hi Norman, before I try that (there is a lot of code in total and your
suggestion would require a lot of changes) is there any reason that you
can see that would result in my code bringing up a Type Mismatch error?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:
http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=507586



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Breaking a UserForm

Hopefully this will give you a clue. I am not sure what Norman Tested that
worked:

Sub aBC()
If "C:\ABC\Myfiles.xls" Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If
End Sub

The above is the situation you create if the user selects file name on the
first showing of the dialog. (this does raise a type mismatch error becuase
the IF is looking for a boolean)


so your "latest" code

If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files
(*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname,
fileFilter:="Excel Files (*.xls), *.xls")

Else: ActiveWorkbook.Close
End If


will raise an error unless the user cancels. If it did work, then you would
show the file SaveAS dialog twice which is pretty lame as well.

--
Regards,
Tom Ogilvy



"Daminc" wrote in
message ...

Hi Norman, before I try that (there is a lot of code in total and your
suggestion would require a lot of changes) is there any reason that you
can see that would result in my code bringing up a Type Mismatch error?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:

http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=507586



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Breaking a UserForm

Hi Tom

I am not sure what Norman Tested that worked:

My apologies, Tom and Daminc.

I re-tested my own code, using Daminc's variable names and, not
surprisingly, it worked. Then, with my mind elsewhere, I responded
nonsensically!.


---
Regards,
Norman



"Tom Ogilvy" wrote in message
...
Hopefully this will give you a clue. I am not sure what Norman Tested
that
worked:

Sub aBC()
If "C:\ABC\Myfiles.xls" Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If
End Sub

The above is the situation you create if the user selects file name on the
first showing of the dialog. (this does raise a type mismatch error
becuase
the IF is looking for a boolean)


so your "latest" code

If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files
(*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname,
fileFilter:="Excel Files (*.xls), *.xls")

Else: ActiveWorkbook.Close
End If


will raise an error unless the user cancels. If it did work, then you
would
show the file SaveAS dialog twice which is pretty lame as well.

--
Regards,
Tom Ogilvy



"Daminc" wrote in
message ...

Hi Norman, before I try that (there is a lot of code in total and your
suggestion would require a lot of changes) is there any reason that you
can see that would result in my code bringing up a Type Mismatch error?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:

http://www.excelforum.com/member.php...o&userid=27074
View this thread:
http://www.excelforum.com/showthread...hreadid=507586







  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Breaking a UserForm


Thanks for your patience :)

My Dim list is:


Code
-------------------
Dim rngNetwork As Range
Dim strNetwork1 As String
Dim strNetwork2 As String
Dim strNetwork3 As String
Dim wrkbkUrl As Workbook
Dim wrkbkname As String
Dim sPath As String
Dim savewrkbkname As String

Set rngNetwork = Range("F11")
strNetwork1 = Range("I11").Text
strNetwork2 = Range("I12").Text
strNetwork3 = Range("I13").Text
wrkbkname = Range("I15").Text
sPath = "P:\VBA training\Excel templates for Network stats\
-------------------


One of the main reasons this code may not be very efficient is that I'
still training and this project has grown somewhat.

Originally I had:

Code
-------------------
savewrkbkname = Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveAs Filename:=savewrkbknam
-------------------

which worked fine until I tried to anticipate actions from a user tha
might scr*w it up. Canceling the save once the saveas dialog box ha
been activated is what brought this attempt at code modification.

The new code allowed me to cancel ok but messed up the save itself.

I shall try and work out how I can use your suggestion to solve thi
problem.

Thanks again for your help :

--
Damin
-----------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...fo&userid=2707
View this thread: http://www.excelforum.com/showthread.php?threadid=50758

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Breaking a UserForm


I've altered the code again but I'm still getting the error:


Code
-------------------
If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveAs Filename:=savewrkbkname

Else:
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
End I
-------------------


The first line is highlighted when I try to 'debug'

--
Damin
-----------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...fo&userid=2707
View this thread: http://www.excelforum.com/showthread.php?threadid=50758

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Breaking a UserForm

This whole approach is flawed. Why not use Norman's suggestiong.

--
Regards,
Tom Ogilvy


"Daminc" wrote in
message ...

I've altered the code again but I'm still getting the error:


Code:
--------------------
If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel

Files (*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname,

fileFilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveAs Filename:=savewrkbkname

Else:
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
End If
--------------------


The first line is highlighted when I try to 'debug'.


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:

http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=507586



  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Breaking a UserForm


Daminc skrev:

If (Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")) Then
savewrkbkname = Application.GetSaveAsFilename(wrkbkname, fileFilter:="Excel Files (*.xls), *.xls")

Else: ActiveWorkbook.Close
End If
--------------------


However, this gave a 'Type Mismatch' error


Isn't it because GetSaveAsFilename returns EITHER the boolean value
false, or the string value you've given in the message box? (And you've
used Dim on the variables.) Try to search (Google) for
GetSaveAsFilename in this news group.

/impslayer, aka Birger Johansson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
breaking during a macro run maxzsim Excel Discussion (Misc queries) 1 March 9th 06 07:51 AM
breaking a link juster21[_2_] Excel Programming 0 July 21st 05 01:29 PM
Breaking Links tojo107 Excel Discussion (Misc queries) 2 July 20th 05 05:40 AM
Breaking Links Guilherme Loretti Excel Discussion (Misc queries) 1 March 9th 05 09:56 PM
breaking out of a loop ChuckM[_2_] Excel Programming 1 December 16th 03 07:07 PM


All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"