BASIC/Visual BASIC Thread

CrazyMike

New Member
If it's jumping to code there's usually a runtime error. I'm guessing this line: Set wb = Workbooks("") is the problem.

What version of excel are you using?

2010..... Do you think it's the file name? Maybe i am entering it wrong? Do you include the "xlsx"?



Also, i messed up in copying that code. actual code in the beginning is:

PHP:
    Dim iRow As Long
    Dim wb As Workbook
    Set wb = Workbooks("Completed Seals 2012")
    Dim ws As Worksheets
    Set ws = Worksheets("Sheet1")
 
Last edited:

Cromewell

Administrator
Staff member
Yes you need the extension. If it's not in the current directory you might need to qualify the path as well.
 

Cromewell

Administrator
Staff member
I think it will be the directory that your excel file is, although I think vbs defaults to 'My Documents' if you don't put the full path in. VBA may be similar.

Are you trying to open the workbook you are currently in? You might be able to just reference the sheet names instead of the workbook.
 

S.T.A.R.S.

banned
To open the file which is not in the current application's folder/directory,you must give it the fully qualified path including the file and it's extension.For example:

C:\VB projects\My project\Book.xlsx
 

CrazyMike

New Member
To open the file which is not in the current application's folder/directory,you must give it the fully qualified path including the file and it's extension.For example:

C:\VB projects\My project\Book.xlsx

This didn't work. Comes up with an error if i type in a file location such as:

Workbooks = Workbooks( C:/users/name/documents/documentname)

Know any other good books or turtorials that would have what i am looking for? lol

Can't believe I'm stuck like this.
 

Matt

New Member
Has anyone tried BBCBasic? BBC Basic For Windows (BB4W) is an increadibly comprehensive and easy to use programming language, and it's easy to understand when it's written down. There's a free demo you can try at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html

I've been using it - or it's predecessors - for the past thirty years. Every time I come up against a problem that seems to be insurmountable, a solution is always forthcoming.

It's just a suggestion, but I'd be interested to see what others think.

Matt
 

bmigga

Member
Got a question for you guys. Very (should be) easy coding. I have to write an IF statement that does the following: (I am VERY VERY new to VB)
---
a) If the LessonType is “Voice” then display the LessonType field value in a bold, blue font (FontBold = True, ForeColor = vbBlue).
---
b) Otherwise, display in normal, black font (FontBold = False, ForeColor = vbBlack) for all other values.
---
Could you tell me if I have it close?
---
If LessonType = "Voice" Then
LessonType.FontBold = True
LessonType.ForeColor = vbBlue
Else
LessonType.FontBold = False
LessonType.ForeColor = vbBlack
End If
 

bmigga

Member
Once again, I am VERY new to Visual Basic. & Obviously the indentions aren't right. (Couldn't do them on this forum)
 

Troncoso

VIP Member
It's been too long since I've used VB, so I don't remember the syntax, but as a tip, when you post code use the [ CODE ][ /CODE ] brackets to keep the formatting (without the spaces):

So:

Code:
If LessonType = "Voice" Then
	LessonType.FontBold = True 
	LessonType.ForeColor = vbBlue
Else
	LessonType.FontBold = False
	LessonType.ForeColor = vbBlack
End If
 

S.T.A.R.S.

banned
VB:

If LessonType = "Voice" Then
LessonType.FontBold = True
LessonType.ForeColor = vbBlue
Else
LessonType.FontBold = False
LessonType.ForeColor = vbBlack
End If


C#:

if(LessonType=="Voice")
{
LessonType.FontBold=true;
LessonType.ForeColor=vbBlue;
}
else
{
LessonType.FontBold=false;
LessonType.ForeColor=vbBlack;
}




Cheers!
 
Top