Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default variable not set

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default variable not set


The last line is missing a Set statement, which is required for all objects...
Set wbDez = ActiveWorkbook

Or maybe you meant...
Emp = ActiveWorkbook.Name
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
Getting inconsistent Error 91-Object variable or With block variable not set mfq Excel Programming 0 December 14th 05 06:08 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 12:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"