Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Issues with ThisWorkbook.Name

I have written a macro that manipulates multiple workbooks. Rather
than require the workbooks to be named a specific name I want to ask
the user for the name and use that within my spreadsheet.

I used the following command to get the file name from the user:

openfilenameA = Application.GetOpenFilename _
(filefilter:="Excel Files (*.xls), *.xls", Title:="Select input
datafile from ADP")

The only problem with the variable "openfilenameA" was that it
contained the full path of the file. My next thought was to open up
the file and then use the command:

ADPFile = ThisWorkbook.Name

My only problem is that once I do this, the value assigned to ADPFile
variable is actually the name of my macro spreadsheet that I am
running.

My process is to have the user open up my macro sheet and then execute
the macro from that. This appears to be getting in the way of things.
Any ideas on how to fix?

Todd

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Issues with ThisWorkbook.Name

I think I'd just use a workbook variable that represents that workbook and never
worry about the name:

Dim OpenFileNameA as variant
dim WkbkA as workbook

openfilenameA = Application.GetOpenFilename _
(filefilter:="Excel Files (*.xls), *.xls", _
Title:="Select input datafile from ADP")

if openfilenamea = false then
exit sub 'user hit cancel
end if

set wkbka = workbooks.open(filename:=openfilenameA)

'then do things by referring to that open workbook

with wkbka.worksheets(1)
.range("a1").value = "hi there!"
end with

wkbka.close savechanges:=true



wrote:

I have written a macro that manipulates multiple workbooks. Rather
than require the workbooks to be named a specific name I want to ask
the user for the name and use that within my spreadsheet.

I used the following command to get the file name from the user:

openfilenameA = Application.GetOpenFilename _
(filefilter:="Excel Files (*.xls), *.xls", Title:="Select input
datafile from ADP")

The only problem with the variable "openfilenameA" was that it
contained the full path of the file. My next thought was to open up
the file and then use the command:

ADPFile = ThisWorkbook.Name

My only problem is that once I do this, the value assigned to ADPFile
variable is actually the name of my macro spreadsheet that I am
running.

My process is to have the user open up my macro sheet and then execute
the macro from that. This appears to be getting in the way of things.
Any ideas on how to fix?

Todd


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Issues with ThisWorkbook.Name

Hi Todd,

Try

ADPFile = ActiveWorkbook.Name

after opening the workbook

--
HTH

Bob Phillips

wrote in message
ups.com...
I have written a macro that manipulates multiple workbooks. Rather
than require the workbooks to be named a specific name I want to ask
the user for the name and use that within my spreadsheet.

I used the following command to get the file name from the user:

openfilenameA = Application.GetOpenFilename _
(filefilter:="Excel Files (*.xls), *.xls", Title:="Select input
datafile from ADP")

The only problem with the variable "openfilenameA" was that it
contained the full path of the file. My next thought was to open up
the file and then use the command:

ADPFile = ThisWorkbook.Name

My only problem is that once I do this, the value assigned to ADPFile
variable is actually the name of my macro spreadsheet that I am
running.

My process is to have the user open up my macro sheet and then execute
the macro from that. This appears to be getting in the way of things.
Any ideas on how to fix?

Todd



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Issues with ThisWorkbook.Name

If you just need to get the filename from a path you could use:

Dim openfilefullnameA As String
Dim openfilenameA As String
openfilefullnameA = Application.GetOpenFilename _
(filefilter:="Excel Files (*.xls), *.xls", Title:="Select input
datafile from ADP")
openfilenameA = LCase$(Mid$(openfilefullnameA, InStrRev(openfilefullnameA,
"\") + 1))


wrote in message
ups.com...
I have written a macro that manipulates multiple workbooks. Rather
than require the workbooks to be named a specific name I want to ask
the user for the name and use that within my spreadsheet.

I used the following command to get the file name from the user:

openfilenameA = Application.GetOpenFilename _
(filefilter:="Excel Files (*.xls), *.xls", Title:="Select input
datafile from ADP")

The only problem with the variable "openfilenameA" was that it
contained the full path of the file. My next thought was to open up
the file and then use the command:

ADPFile = ThisWorkbook.Name

My only problem is that once I do this, the value assigned to ADPFile
variable is actually the name of my macro spreadsheet that I am
running.

My process is to have the user open up my macro sheet and then execute
the macro from that. This appears to be getting in the way of things.
Any ideas on how to fix?

Todd



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
ThisWorkbook of personal.xls Jack Sons Excel Discussion (Misc queries) 4 August 29th 07 04:28 PM
ThisWorkbook Ron[_28_] Excel Programming 9 January 3rd 05 10:51 PM
ThisWorkbook.Protect Jack Sheet Excel Programming 2 December 7th 04 11:38 AM
ThisWorkbook.FullName Steph[_3_] Excel Programming 3 November 23rd 04 08:41 PM
How to use: ThisWorkbook module RichardG Excel Programming 2 October 21st 04 12:44 AM


All times are GMT +1. The time now is 11:36 PM.

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

About Us

"It's about Microsoft Excel"