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
Plus One Google
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

resolvedResolved · High Priority · Version 2003

replyReplyWed 10 Mar 2010, 11:51Delegate Tracey said...

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

For upcoming training course dates see: Pricing & availability

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

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

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

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

 

 

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

Excel tip:

Selecting your working range

In excel if you have an area you want to highlight, press Ctrl + * or Ctrl+Shift+8 (to get the *). This will select your working range.

View all Excel hints and tips

forum postHOW DO YOU LINK EXCEL TO THE WEB?

» Forum post: Web

article

Staying In Touch: The Best Way To Manage Teams Remotely

Managing teams remotely means doubling the amount of hassle and complication involved in normal team management. But the key to getting it right is maintaining a strong virtual presence.

» Article: Managing teams remotely onsite training uk


Rate this page:
2.2/5 (213 votes cast)
Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses
Microsoft Certified Partner
Security Seal verified by visa, mastercard securecard

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

Management training

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

Consultancy
Application Development

Blogs

Excel Training
MS Project Training
Microsoft Training Blog

Version differences

Office 2010 vs 2007
MS Project version differences

Training Information

London Computer Training
Computer Training London
Docklands Training Courses
Docklands Training London

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

Training Articles
Training Information

Microsoft training

Microsoft Office training
& IT Applications

Microsoft Project 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
Microsoft.training
(more...)

Excel Training

Excel courses
Excel Training Courses Medway
Autonumber in Excel
Microsoft Excel training
Basic Excel Courses
Basic Excel Course
Basic Excel Training

Interested in MS Access training?

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

Training provider

Training providers
IT training companies
IT training providers
Management Training providers
Management Training provider

Event history, feedback results
Events in 2012 · 2011 · 2010 · More

See also

Crystal Reports training