1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

    Yours,
    Chandoo
  2. 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...

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

Registering To VBA Project

Discussion in 'VBA Macros' started by mrmohit1a, May 13, 2017.

  1. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    I have made an excel implementation. I have to make a new development in it to make it secure from others. I want the program to check a text file with 1 (or applicable with n+1 formula) if it exist with the value 1 (or n+1 formula) so the workbook will proceed otherwise it will end.
    Anyone please help me with it.
    Thanks in advance
  2. Monty

    Monty Well-Known Member

    Messages:
    721
    Hello mrmohit1a

    Welcome to forum.

    Not so clear with your question..
  3. Monty

    Monty Well-Known Member

    Messages:
    721
    Hello mrmohit1a

    May be sample file with your question will help to answer.
  4. Marc L

    Marc L Excel Ninja

    Messages:
    3,027
  5. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    I need a vba code to be applied on my vba project. Which will find a text file in a specified path with the value n+1. if it exist the program will go on otherwise it will close.
    Something like this
    Dim txt As String, FilePath As String, n As Integer
    FilePath = ThisWorkbook.Path & "\download.txt"
    Open FilePath For Input As #1
    n = 1
    Do Until EOF(1)
    Line Input #1, txt
    n = n + 1: Sheets("Register").Cells(1, n - 1)
  6. Monty

    Monty Well-Known Member

    Messages:
    721
    Which will find a text file in a specified path with the value n+1?
  7. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    the code will find a text file in a specified path with the value n+1
    Now its ok
    Did u understand
  8. Monty

    Monty Well-Known Member

    Messages:
    721
    You meen text file with name n+1?
  9. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    No bro the text file will consist n+1 where n<7 n=0,1,2,3,4,5,6,7+1 OK

    Uploaded file named key.txt which the code will help in finding it, which consists of value n+1 BUT in uploaded file it consists the value 1 which can be written as n+1(where n=0+1 which gives 1)

    Attached Files:

    • key.txt
      File size:
      1 bytes
      Views:
      4
    Monty likes this.
  10. Monty

    Monty Well-Known Member

    Messages:
    721
    Thanks for sharing..
  11. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    No problem
    Can U solve the problem of mine
  12. Marc L

    Marc L Excel Ninja

    Messages:
    3,027

    Use code tags or icon when posting a code …

    Dir VBA function can test if a file exists, returns an empty string if not …
  13. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    no bro i tried doing it
  14. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    Anyone please help me with it
  15. vletm

    vletm Well-Known Member

    Messages:
    2,544
    mrmohit1a
    You want to check from "download.txt" ... no ... from "key.txt"
    that is there some values ... hmm?
    Both files could copy to anywhere ...
    and after that it will enable to use development with everyone.
    What is connection with 'registering to VBA Project'?
    What would be Your problem? (#11 Reply)
  16. Derek McGill

    Derek McGill Active Member

    Messages:
    129
    You may have to find the .txt file first then open it and then use what value is in the file.
  17. Derek McGill

    Derek McGill Active Member

    Messages:
    129
    This might get you started :-
    Code (vb):

    If My.Computer.FileSystem.FileExists("c://Check.txt") Then
    MsgBox("File found.")
    Else
    MsgBox("File not found.")
    End If
     
    Monty likes this.
  18. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    IF command should contain the n+1 value that check is it applicable to the txt file or not
  19. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    Thank you but i have used it but not able to check n+1 by it.
  20. vletm

    vletm Well-Known Member

    Messages:
    2,544
    mrmohit1a
    Okay - no answers from You ... but test next sample
    Code (vb):

    Sub do_mrmohit1a()
        Application.ScreenUpdating = False
        ALL_OK = False
        On Error Resume Next
        Workbooks.OpenText ("key.txt")
        If Err.Number = 0 Then
            n = ActiveSheet.Range("A1")
            Workbooks("key.txt").Close
            Err.Clear
            If Sheets("Register").Cells(1, n) = n Then ALL_OK = True
            If Err.Number <> 0 Then ALL_OK = False
        End If
        If Not ALL_OK Then
            MsgBox "Bye Bye"
    '   change next to wanted 'Exit' after testing
           Exit Sub
        End If
    End Sub
     
    Ps1. Only You could know Your workbook details => You need to modify that code - as You know!

    Ps2. No need that "Bye Bye"
  21. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    Bro i dont think that the file will in the specified path
    and i have a doubt that does it contain n+1 formula applicable inside the text file
    Last edited: May 15, 2017
  22. vletm

    vletm Well-Known Member

    Messages:
    2,544
    mrmohit1a - sister?
    1) No matter, what do You think, I've just tried to read You texts
    Your sample has named that path! ... no need to use that kind of case!
    2) Have You checked Your sent 'key.txt'-file Yourself?
    There is 'only' one!
    3) What kind of doubt You have?
    Did You test my macro?
    What is missing?
    Need facts!
  23. mrmohit1a

    mrmohit1a New Member

    Messages:
    17
    vletm --> grandmother
    I think all things is missing. can you edit the code according to my needs and then gimme
  24. vletm

    vletm Well-Known Member

    Messages:
    2,544
    mrmohit1a - mission impossible!
    1) If cannot open file which You have named,
    2) from Your named folder
    3) read it's value
    4) if not file found or not correct value then make ('need to modify') end
    If all those missing from my code
    then what are Your needs?
    Chirag R Raval likes this.
  25. Monty

    Monty Well-Known Member

    Messages:
    721
    Mr mrmohit1a
    Sorry to say!
    Somebody volunterly helping from there busy schedule respect them!
    Chirag R Raval likes this.

Share This Page