View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1991_] Rick Rothstein \(MVP - VB\)[_1991_] is offline
external usenet poster
 
Posts: 1
Default variable not set

To follow up on Jim's response to you, the error is being generated because
you declared the wbDez variable to be of type Workbook, but you are trying
to assign a simple String data type to it (the Name property of the
ActiveWorkbook is a text String, not a workbook object).

I would also like to point out that one of your Dim statements is not doing
what you think it is, and more than likely neither are two of your other
ones (I can't tell for sure because the snippet of code you provided doesn't
make use of the variables declared in them). The one I am sure of is this
one...

Dim FicDez, FicMov, FicCar As String

In the above statement, **only** the variable named FicCar is declared as a
String variable; the other two are getting declared as Variants. Unlike many
other languages, VB requires that all variables be declared individually as
to their type and, if that is not done, they default to being declared as
Variants. So, if you did not want to declare each of those variables in
individual Dim statements (my personal choice on how to do it), you would
need to modify that above statement like this...

Dim FicDez As String, FicMov As String, FicCar As String

The other two Dim statements that probably need to be modified (for the same
reason as discussed above) are these...

Dim UlinDez, UlinMovOr, UlinCarOr, UlinMovFn, UlinCarFn As String
Dim Emp, Mes As String

Rick



"Raul Sousa" wrote in message
...
I have this code, I wrote.
I am not very confortable with VBA, so I have a problem.

When it arrives at the last line it gives an error. Run-time error, 91 :
€œvariable not set€.

I cant understand why.

Dim UlinDez, UlinMovOr, UlinCarOr, UlinMovFn, UlinCarFn As String
Dim wbDez As Workbook
Dim wbMov As Workbook
Dim WbCar As Workbook
Dim FicDez, FicMov, FicCar As String
Dim Emp, Mes As String

FicDez = Application.GetOpenFilename
FicMov = Application.GetOpenFilename
FicCar = Application.GetOpenFilename

Mes = Application.InputBox("Indicar o mês")

Workbooks.OpenText Filename:=FicDez _
, Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited,
Semicolon:=True, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1),
Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1)), TrailingMinusNumbers:=True

wbDez = ActiveWorkbook.Name