Why is the error in this VBA code? [closed] - vba

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
When I run this VBA code, I get an error.
Option Explicit
Sub CreateBorder()
ActiveCell.CurrentRegion.BorderAround
LineStyle:=xlDot, Weight:=xlThick, Color=RGB(255,0,0)
End Sub
The error seems to come up in the Sub CreateBorder() line. What is the problem?

There are two issues:
you can't split a statement across two lines (unless you use a _ at the end of the first line)
parameters names need to be followed by := (you use Color=...)
So it can be:
ActiveCell.CurrentRegion.BorderAround LineStyle:=xlDot, Weight:=xlThick, Color:=RGB(255, 0, 0)
or
ActiveCell.CurrentRegion.BorderAround _
LineStyle:=xlDot, Weight:=xlThick, Color:=RGB(255, 0, 0)

Related

How do I count files in a folder based on their sizes using visual basic .net (vb.net)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to count files in a folder based on their sizes. For example, how many files that are less than 512KB and how many files that are more than 512KB. Please help me.
Below sub-routine will help you to get the count
Sub GetFileDetails(ByVal sFolderPath As String, ByRef Filelessthan512KB As Integer, ByRef FileMorethan512KB As Integer)
Dim sFiles() As String = Directory.GetFiles(sFolderPath)
For Each file As String In sFiles
Dim oFileDetails As New FileInfo(file)
If (oFileDetails.Length / 1024) < 512 Then
Filelessthan512KB = Filelessthan512KB + 1
Else
FileMorethan512KB = FileMorethan512KB + 1
End If
Next
End Sub

How to call a function and give it a string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Okay, I want to call the function OpenApp() (located in a class called API.vb), but when calling it I want to pass a string to it like that:
API.OpenApp("Settings")
That's good, but how can I detect that this string has been passed, like so the function knows there's a string?
if you want to do this then you need to add a definition to the OpenApp() function so the function know what he should do with "settings" strings.
Private Sub OpenApp(dial As String)
Select Case dial
Case "settings"
MsgBox("lol")
Case "something"
MsgBox("ok")
End Select
End Sub

check a specific character in textbox visual basic? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Lets say i have a textbox containing the string "hello".
Is there a way in which can i check that the 3rd character of textbox.text = "l"?
We are talking about visual basic, of course.
Thanks!
You could use this function
Private Function checkCharacter(thisString As String,
searchCharacter As Char,
index As Integer)
Try
Return thisString(index) = searchCharacter
Catch
Return False
End Try
End Function
Call it like this
Dim result As Boolean = checkCharacter(TextBox1.Text, "l"c, 2)

Visual Basic - Selection start / end position [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
im currently stuck on a problem with visual basic. I need to get the start and the end of the selection, in the example on the image it should be 12/19. Couldnt find anything on the internet.. I guess im just to stupid... Hope you can help me
Not clear from the question, but it looks like a TextBox control on a UserForm. If that's the case, then you can get the start and end of the current selection using the SelStart and SelLength properties:
Dim p1 As Long
p1 = TextBox1.SelStart
Dim p2 As Long
p2 = p1 + TextBox1.SelLength
If that is a System.Windows.Controls.TextBox then you can use the selection properties:
.SelectionStart
.SelectionLength

VBA Call Method based on a string value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If I declared an array of strings, and the strings are each a Sub name, how can I call the Sub of that name without needing an if statement?
Example pseudo code:
Set String Array = {"sub1","sub2","sub3"}
for each String str in Array
call str 'where str is a Sub
next str
I do know how to create an array and call Subs; I just don't know how to call a Sub using a string value.
Try this:
Application.Run (str)
I just learned about this by doing something similar. You can also pass a variable to that sub by doing:
Application.Run (str, "YourValue")