excel vba switching between
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training Sitemap add this page to your favourites/bookmarksBookmark page

view a printable version of this pagePrintable version
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and Help » Excel VBA switching between workbooks

Excel VBA switching between workbooks

The UK's most regular instructor-led training courses.
Training information: excel+courses+in+london · Microsoft+excel+training · VBA courses London

resolvedResolved · High Priority · Version 2003

No ranking yet
5 posts
replyReplyWed 10 Mar 2010, 11:51Delegate Tracey said...

Tracey has attended:
Excel Advanced course
Excel VBA Intro Intermediate course

Excel VBA switching between workbooks

Hi, Would you be able to advise why this code does not work:

Sub Hyperlinks()
''Set up hyperlinks
Workbooks.Open ("I:\DATA\Enterprise\Peugeot EQC\PSA Bimarques\Project\Peugeot Bi-marque Final 10Mar10.xls")
BimarquesFinal = ActiveWorkbook.Name
Sheets(1).Select

For y = 3 To 57

Dim HyperAddress As String
HyperAddress = "'" & ThisWorkbook.Sheets("Contents list").Cells(y, 2).Value & "'!A1"
Workbooks(BimarquesFinal).Sheets(2).Cells(y, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
HyperAddress, TextToDisplay:= _
Workbooks(BimarquesFinal).Sheets("Workbook Contents").Cells(y, 1).Value

Next y

The line which does not work is:

Workbooks(BimarquesFinal).Sheets(2).Cells(y, 1).Select

Basically, all I want to do is, once I've picked up my HyperAddress values from the workbook which contains the VBA, go back to the workbook which I've just opened and select a cell on sheet 2! I've tried a number of things and can't seem to find a way of specifying this without it falling over.

Thanks

Tracey

Excel Advanced 1 day course
Version Date Location Places
available
Book Next place rate (£) List
price
Pay by
Card
Pay by
Invoice
2007 Mon 2 Aug 2010 Southwark 3 Book now £240 £245£245
2003 Thu 5 Aug 2010 Southwark 4 Book now £240 £245£245
2010 Fri 6 Aug 2010 Bloomsbury 0 FULL    £299
2007 Tue 10 Aug 2010 Bloomsbury 0 FULL    £245
2003 Tue 10 Aug 2010 Limehouse 5 Book now £235 £240£245
2007 Fri 13 Aug 2010 Limehouse 8 Book now £229 £234£245
Full Schedule: See all 134 Excel Advanced course dates.
Bookings currently available until 28th September 2011.

Platinum
825 posts
replyReplyThu 11 Mar 2010, 09:51Trainer Stephen said...

RE: Excel VBA switching between workbooks

Hi Tracey

Thanks for your question

Could you clarify something for me? When your code falls over does it generate a run time error. If so what is the number and description?

Thanks

Stephen

No ranking yet
5 posts
replyReplyThu 11 Mar 2010, 10:02Delegate Tracey said...

RE: Excel VBA switching between workbooks

Hi Stephen,

Yes, it's run-time error 1004 - "Select method of Range class failed".

Tracey

Platinum
825 posts
replyReplyWed 17 Mar 2010, 11:47Trainer Stephen said...

RE: Excel VBA switching between workbooks

Hi Tracy

Thanks for the update. Sorry about the delay in getting back to you, I've been down with flu.

Your problem is that you can only select a cell in the active worksheet. In your code, before the loop you select sheet 1 and then in the loop you try to select a cell in sheet 2.

If you select sheet 2 before the loop that should solve the problem

Regards

Stephen

No ranking yet
5 posts
replyReplyWed 17 Mar 2010, 13:39Delegate Tracey said...

RE: Excel VBA switching between workbooks

Thanks. So, for future reference, you cannot select a cell without first having selected the worksheet? You cannot select both a worksheet and a cell with the same line of code?

Could I also have achieved the same result by selecting the worksheet on one line and the cell on the next line?

Tracey

---

Sub Hyperlinks()
''Set up hyperlinks
Workbooks.Open ("I:\DATA\Enterprise\Peugeot EQC\PSA Bimarques\Project\Peugeot Bi-marque Final 10Mar10.xls")
BimarquesFinal = ActiveWorkbook.Name

For y = 3 To 57

Dim HyperAddress As String
HyperAddress = "'" & ThisWorkbook.Sheets("Contents list").Cells(y, 2).Value & "'!A1"
Workbooks(BimarquesFinal).Sheets(2).Select
Cells(y, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
HyperAddress, TextToDisplay:= _
Workbooks(BimarquesFinal).Sheets("Workbook Contents").Cells(y, 1).Value

Next y


Related articles

· Want To Use Excel To Calculate Your Mortgage Repayments?
· Excel Course Tips and Tricks to Liven Up Your Excel Spreadsheets
· Reporting and Analysis with Excel
· Mastering Page Layout In Excel
· Correct In, Garbage Out

Please browse our web site to find out more about
excel+courses+in+london and other Microsoft training courses.

Excel tip:

Printing spreadsheets without opening them first

Here's a fast way of printing a spreadsheet from Windows Explorer/My Computer.

Go to the location where the spreadsheet is saved on your computer, then right-click on the icon next to the document and select Print from the menu.

The spreadsheet will automatically open, print and close itself.

View all Excel hints and tips


Rate this page:
2.2/5 (127 votes cast)
Institute of IT Training - Accredited Training Provider ILM
Microsoft Certified Partner
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Association of Computer Trainers verified by visa, mastercard securecard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Professional & Management

Professional Skills courses
Project Management Course London
Project Management Courses London
Project Management Training London
Project Management Training
Project Seminar
Project Seminars
Time Management Course London
Time Management London
Time Management Courses London
Time Management Training London
Introduction to Finance course
Assertiveness Skills course
Effective Communications Skills training
Presentation Skills London

Training Formats

Public scheduled courses
On-site training
Closed company courses

MS Office & IT Applications

Excel courses
Excel training
Excel Training Courses Medway
Microsoft Excel training
Microsoft Project training
Microsoft Office training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training
MS Project courses
MS Project training
Outlook courses
PowerPoint courses
PowerPoint training
VBA courses
Word courses
(more...)

Crystal Reports training

DreamWeaver courses
Dreamweaver training

Training Information

London Computer Training
Computer Training London

Training venues
Client list
FAQ
Pricing and availability
Course details / Syllabus

Training Information
Training Articles
Microsoft Training Blog

Interested in Access training?
Please see the following pages:

Access courses
Access training
Microsoft Access training
Microsoft access courses
Microsoft training access course
Microsoft+access+training
Access courses in london