Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

Thanks so much for having a place for us propeller heads to hang out and chat.

Geography

Where in the world do Tek-Tips members come from?

Store date from cell in spreadsheet to a temporary variable

Delindan (MIS)
11 Jun 12 15:31
This seems like it should be really simple but I can't figure it out. The format of the report that I receive has the date in one cell at the top and the remainder of the data in another place so I would like to grab that date and store it to a variable to that when I import the data to my table I can add the date to all the records. I've always used the transferspreadsheet which doesn't seem like it would work in this situation. Any ideas? Thanks!
Delindan (MIS)
12 Jun 12 14:35
So I decided to try and create a named range so that I could just import it and be able to grab the date that way and am having trouble with the syntax. I recorded a macro in excel and copied and pasted so I was thinking it would be simple...not. Here's what I have:

With xlApp
.Visible = False
Set WB = .Workbooks.Open(strFileName)
Application.Goto Reference:="R54C2"
ActiveWorkbook.Names.Add Name:="info", RefersToR1C1:="=Sheet1!R54C2"
ActiveWorkbook.Names("info").Comment = ""
.Workbooks(1).Save
.Workbooks(1).Close
End With

It errs out on the application.goto line. Any thoughts...am I going in the wrong direction?

Thanks!
SkipVought (Programmer)
12 Jun 12 14:40


you already have a reference to the Excel APPLICATION...

CODE

With xlApp
.Visible = False
Set WB = .Workbooks.Open(strFileName)
.sheets(1).Goto Reference:="R54C2"
wb.Names.Add Name:="info", RefersToR1C1:="=Sheet1!R54C2"
wb.Names("info").Comment = ""
wb.Save
wb.Close
End With

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

PHV (MIS)
12 Jun 12 14:41
What about this ?

CODE

With xlApp
.Visible = False
Set WB = .Workbooks.Open(strFileName)
.Goto Reference:="R54C2"
WB.Names.Add Name:="info", RefersToR1C1:="=Sheet1!R54C2"
WB.Names("info").Comment = ""
WB.Save
WB.Close
End With

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Andrzejek (Programmer)
12 Jun 12 15:16

Quote:

the report [...] has the date in one cell at the top [...] I would like to grab that date and store it to a variable

Where, which cell, is the date you want to 'grab'?

Have fun.

---- Andy

Delindan (MIS)
12 Jun 12 17:50
I receive a report in excel each month that has data I am importing to a temporary table in access. The report has one date in a particular cell (B54) that is the same location each month. In my routine I would like to import the data to the temp table then append all records to the permanent with the date that is in this cell. I've got everything working except the date. What would be great is to have a variable that I could somehow store the contents of the cell (B54) into so that I could use the variable in my append routine. The only way I've grabbed data from excel is through a docmd.transferspreadsheet command. It doesn't work so nicely for one cell of information though. Any thoughts?
sxschech (TechnicalUser)
13 Jun 12 11:45
I'm grabbing a date from an excel file, but did it without code as at the time I set it up didn't know how to code it. What I did was save the excel file or rename it to a standard name each week and then linked the cell via an sql statement. Then I did a dlookup to grab the date for use in queries, code, etc.

Here is a sample of the sql statement:

CODE -->

SELECT T1.*
FROM [Excel 8.0;HDR=NO;IMEX=1;Database=c:\temp\datafile.xls].[Sheet1$B1:B1] as T1;

I found this from:
http://www.accessmvp.com/KDSnell/EXCEL_Import.htm#...
SkipVought (Programmer)
13 Jun 12 11:57
Ths workbook that you receive:

Are there multiple worksheets or just one sheet?

If just one, isn't that data in your temp table after import?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Delindan (MIS)
13 Jun 12 12:05
I had been importing just the select range that had the records of interest in them. I just decided prior to your post that I should just import everything and then should be able to grab the date that way. I'm still working out kinks here but I think it's stuff I can handle. Thanks to all for input!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close