• 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...

  • 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

mrmohit1a

New Member
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
 
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)
 
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)
 

Attachments

  • key.txt
    1 bytes · Views: 5

Use code tags or icon when posting a code …

Dir VBA function can test if a file exists, returns an empty string if not …
 
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)
 
This might get you started :-
Code:
If My.Computer.FileSystem.FileExists("c://Check.txt") Then
MsgBox("File found.")
Else
MsgBox("File not found.")
End If
 
mrmohit1a
Okay - no answers from You ... but test next sample
Code:
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"
 
mrmohit1a
Okay - no answers from You ... but test next sample
Code:
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"
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:
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!
 
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!
vletm --> grandmother
I think all things is missing. can you edit the code according to my needs and then gimme
 
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?
 
Back
Top