VBA Userchecksubroutine skips code

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Hi when i execute this code:
VBA Code:
Sub FileSystemObj()
Sheets("KARTA REALIZACJI").Visible = True
Application.ScreenUpdating = False
  Dim line As String
  Dim FSO As Object
  Dim TS As Object
  Dim PATH As String
  Dim usercheck As String
  usercheck = InputBox("Podaj hasło dostępu", "Hasło")
  
  If usercheck = "witek" Then
  Sheets("Admin").Range("CurrentUsr").Value = "Witold"
        PATH = Sheets("Admin").Range("A31").Value
    ElseIf usercheck = "konrad" Then
    Sheets("Admin").Range("CurrentUsr").Value = "Konrad"
        PATH = Sheets("Admin").Range("A32").Value
    ElseIf usercheck = "damian" Then
    Sheets("Admin").Range("CurrentUsr").Value = "Damian"
        PATH = Sheets("Admin").Range("A33").Value
    ElseIf usercheck = "admin" Then
    Sheets("Admin").Range("CurrentUsr").Value = "Mariusz"
        PATH = Sheets("Admin").Range("A34").Value
    Else: MsgBox "Błędne hasło": Exit Sub
          
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set TS = FSO.OpenTextFile(PATH)
  Sheets("KARTA REALZIACJI").Range("B150").Select
  Do While Not TS.AtEndOfStream
     line = TS.ReadLine
     ActiveCell = line
     ActiveCell.Offset(1, 0).Select
  Loop
  TS.Close
  Set TS = Nothing
  Set FSO = Nothing
Application.ScreenUpdating = True
Sheets("KARTA REALZIACJI").Range("D148").Value = Date
End If
Sheets("KARTA REALIZACJI").Visible = False
End Sub
after usercheck all of this is skipped:
VBA Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
  Set TS = FSO.OpenTextFile(PATH)
  Sheets("KARTA REALZIACJI").Range("B150").Select
  Do While Not TS.AtEndOfStream
     line = TS.ReadLine
     ActiveCell = line
     ActiveCell.Offset(1, 0).Select
  Loop
  TS.Close
  Set TS = Nothing
  Set FSO = Nothing
Application.ScreenUpdating = True
Sheets("KARTA REALZIACJI").Range("D148").Value = Date
I run this code a lot without usercheck in a different **** withotu a problem.
Any idea why this happens?
 
Does the indenting actually matter other than visual refference?
It doesn't affect the way the code works but it should make the structure more obvious, which usually helps to figure out why the code is not doing what you want.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,982
Messages
6,122,575
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top