The following macro does what you want.  Note it must be named Auto_Open to
run automatically when the workbook is opened.
Sub Auto_Open()
    '
    '   When Workbook is opened if Cell A1 is empty create
    '   a text file having same name as the WorkBook
    '
    If Cells(1, 1).Value = "" Then
        Filename = Replace(ThisWorkbook.Name, ".xls", "")
        FilePath = "c:\" & Filename & ".txt"

        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile(FilePath, True)

        a.WriteLine String(15, "*") & "  EMPTY  " & String(15, "*")

        a.Close
    End If

Tom

End Sub

On Tue, Dec 23, 2008 at 7:28 AM, Samir Agayev <saga...@gmail.com> wrote:

>
> Dear Members,
>
> Is it possible to create a text file on condition?
>
> For example, when file opens, vba should check whether A1 cell is empty or
> not. If empty it automatically create a text file, and put the word "empty"
> in it.
>
> Is that possible?
>
> If not does anyone tell me how can I access "cells" in Excel from VB
> Express?
>
> Thank you in advance.
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To post to this group, send email to excel-macros@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/excel-macros?hl=en

Visit & Join Our Orkut Community at 
http://www.orkut.com/Community.aspx?cmm=22913620

Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com

To see the Daily Excel Tips, Go to:
http://exceldailytip.blogspot.com
-~----------~----~----~----~------~----~------~--~---

Reply via email to