Hello,

Thank you for your reply is there any way where I can simplify this code.

Thank you

Chandra Shekar

On Mon, Dec 13, 2010 at 7:39 PM, Paul Schreiner <schreiner_p...@att.net>wrote:

>  So.. your macro seems to be creating a new file with a name
> defined with wrkbk_nm1
>
> Now, you want to check to see if the file exists and if it does,
> treat it as an Error?
>
> well.. the logic is somewhat odd, but I can at least point you in the right
> direction.
>
> Check out the FileSystem Object.
>
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> then:
>
> if fso.fileexists(wrkbk_nm1) then goto Errorhandler
>
>
>
> Paul
>
>
> *From:* Chandra Shekar <chandrashekarb....@gmail.com>
> *To:* excel-macros@googlegroups.com
> *Sent:* Mon, December 13, 2010 7:22:00 AM
> *Subject:* $$Excel-Macros$$ Error Handler
>
> Hi,
>
> What is the error in the below code, here I am checking the existence of
> file in "C:\Documents and Settings\Administrator\Desktop\Output\". If exist
> it should goto error handler and come out from whole program. Please let me
> know whats the error is.
>
> Sub create_wrkbk(ByRef wrkbk_nm As String)
> Application.DisplayAlerts = False
> On Error GoTo errorhandler
> ext_wrkbknm = Mid(wrkbk_nm, 1, InStr(1, wrkbk_nm, ".") - 1)
> wrkbk_nm = ext_wrkbknm & ".xls"
> wrkbk_nm1 = wrkbk_nm
> Set nwrkbk = Application.Workbooks.Add
> wrkbk_nm = "C:\Documents and Settings\Administrator\Desktop\Output\" &
> wrkbk_nm
> nwrkbk.SaveAs wrkbk_nm
> ThisWorkbook.Worksheets(1).UsedRange.Copy
> Application.Workbooks(wrkbk_nm1).Activate
> Application.Workbooks(wrkbk_nm1).Worksheets(1).Range("A1").Select
> Application.Workbooks(wrkbk_nm1).Worksheets(1).Range("A1").PasteSpecial
> Application.Workbooks(wrkbk_nm1).Worksheets(1).Range("A1").Select
> Application.Workbooks(wrkbk_nm1).Close True
> On Error GoTo 0
> Exit Sub
> errorhandler:
> MsgBox Err.Description
> Application.DisplayAlerts = True
> End
> End Sub
>
> --
>
> ----------------------------------------------------------------------------------
> Some important links for excel users:
> 1. Follow us on TWITTER for tips tricks and links :
> http://twitter.com/exceldailytip
> 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
> 3. Excel tutorials at http://www.excel-macros.blogspot.com
> 4. Learn VBA Macros at http://www.quickvba.blogspot.com
> 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>
> To post to this group, send email to excel-macros@googlegroups.com
>
> <><><><><><><><><><><><><><><><><><><><><><>
> Like our page on facebook , Just follow below link
> http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts
>
>   --
>
> ----------------------------------------------------------------------------------
> Some important links for excel users:
> 1. Follow us on TWITTER for tips tricks and links :
> http://twitter.com/exceldailytip
> 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
> 3. Excel tutorials at http://www.excel-macros.blogspot.com
> 4. Learn VBA Macros at http://www.quickvba.blogspot.com
> 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>
> To post to this group, send email to excel-macros@googlegroups.com
>
> <><><><><><><><><><><><><><><><><><><><><><>
> Like our page on facebook , Just follow below link
> http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts
>

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts

Reply via email to