ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA question - getting name of workbook (https://www.excelbanter.com/excel-programming/295134-vba-question-getting-name-workbook.html)

ajliaks[_5_]

VBA question - getting name of workbook
 
hey!

I have this question:

I open workbook "File A" and save its name like

Dim FA as VAriant
FA = ActiveWorkbook.name

Now I open Workbook "File B" and save its name like:

Dim FB as Variant
FB = ActiveWorkbook.name

The problem is that FA now takes the same value of FB, and I need t
use the first value!

What can I do?

Thanks

--
Message posted from http://www.ExcelForum.com


kkknie[_41_]

VBA question - getting name of workbook
 
What exactly are you trying to do and where are you trying to do it?
That is, where is the code running from and how is it run?

I'm on a slow connection with a couple of screaming kids, so excuse i
I cannot post back that quickly. :)



--
Message posted from http://www.ExcelForum.com


Vasant Nanavati

VBA question - getting name of workbook
 
From the Immediate Window:

FA = ActiveWorkbook.name
Debug.Print FA
Book1

'Open new workbook
FB = ActiveWorkbook.name
Debug.Print FB
Book2
Debug.Print FA
Book1

I don't see the problem.

--

Vasant


"ajliaks " wrote in message
...
hey!

I have this question:

I open workbook "File A" and save its name like

Dim FA as VAriant
FA = ActiveWorkbook.name

Now I open Workbook "File B" and save its name like:

Dim FB as Variant
FB = ActiveWorkbook.name

The problem is that FA now takes the same value of FB, and I need to
use the first value!

What can I do?

Thanks.


---
Message posted from http://www.ExcelForum.com/




Paulw2k

VBA question - getting name of workbook
 
Hi Ahliaks,

Your last premise is wrong. FA holds the value "FileA.xls", FB holds the
value "FileB.xls.
Also avoid declaring variables as variant if possible. Here the file names
are just text so use String.

Dim FA as String
Dim FB as String

FA = ActiveWorkbook.Name
Workbooks.open "filepath/FileB.xls"
FB =ActiveWorkbook.Name

To get hold of "FileA.xls" again
Workbooks(FA).Activate
......

To return to "FileB.xls"
Workbooks(FB).Activate


Hope that helps

Paul






"ajliaks " wrote in message
...
hey!

I have this question:

I open workbook "File A" and save its name like

Dim FA as VAriant
FA = ActiveWorkbook.name

Now I open Workbook "File B" and save its name like:

Dim FB as Variant
FB = ActiveWorkbook.name

The problem is that FA now takes the same value of FB, and I need to
use the first value!

What can I do?

Thanks.


---
Message posted from http://www.ExcelForum.com/




Dave Peterson[_3_]

VBA question - getting name of workbook
 
Or even:

Dim WkbkA as workbook
Dim WkbkB as workbook

set wkbkA = activeworkbook

set wkbkB = Workbooks.open(filename:="filepath/FileB.xls")

wkbkA.activate

===
But you don't usually need to select/activate stuff to work with it.

maybe just things like:

with wkbkA.worksheets("sheet1")
.range("a1").value = "Hi there!"
end with



Paulw2k wrote:

Hi Ahliaks,

Your last premise is wrong. FA holds the value "FileA.xls", FB holds the
value "FileB.xls.
Also avoid declaring variables as variant if possible. Here the file names
are just text so use String.

Dim FA as String
Dim FB as String

FA = ActiveWorkbook.Name
Workbooks.open "filepath/FileB.xls"
FB =ActiveWorkbook.Name

To get hold of "FileA.xls" again
Workbooks(FA).Activate
......

To return to "FileB.xls"
Workbooks(FB).Activate

Hope that helps

Paul

"ajliaks " wrote in message
...
hey!

I have this question:

I open workbook "File A" and save its name like

Dim FA as VAriant
FA = ActiveWorkbook.name

Now I open Workbook "File B" and save its name like:

Dim FB as Variant
FB = ActiveWorkbook.name

The problem is that FA now takes the same value of FB, and I need to
use the first value!

What can I do?

Thanks.


---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson



All times are GMT +1. The time now is 10:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com