473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I Open an Existing Workbook from my Procedure

1 New Member
How can I open an existing Workbook within my procedure?

I need something to use instead of line #8.
Expand|Select|Wrap|Line Numbers
  1. Private Sub View_Record_Click()
  2. Dim objXL As Object
  3. Dim newbook As Excel.Workbook
  4. Dim newsht1 As Excel.Worksheet
  5.  
  6. Set objXL = CreateObject(Class:="Excel.Application")
  7.  
  8. Set newbook = objXL.Workbooks.Add 
  9. ' Here instead of add, i want add already existing worksheet
  10.  
  11. Set newsht1 = newbook.Sheets("Sheet1")
  12.  
  13. newsht1.Shapes.AddShape(msoShapeRectangle, 89.25, 72.75, 113.25, 92.25).Select
  14. objXL.Visible = True
  15. End Sub
Feb 7 '12 #1
2 1489
MikeTheBike
639 Recognized Expert Contributor
Hi

You have not indicated how/where you are going to determine the file path (or file name) but you can use the FileDialog object to 'pick' the file you want to open.

Access help offers this bit of code which, with a little research, will enable you to obtain a file path/name by selecting it.
Expand|Select|Wrap|Line Numbers
  1. Dim dlgOpen As FileDialog
  2.  
  3. Set dlgOpen = Application.FileDialog( _
  4.     FileDialogType:=msoFileDialogOpen)
  5.  
  6. With dlgOpen
  7.     .AllowMultiSelect = True
  8.     .Show
  9. End With
HTH


MTB
Feb 7 '12 #2
NeoPa
32,557 Recognized Expert Moderator MVP
You may find the following articles helpful :
  1. Select a File or Folder using the FileDialog Object.
  2. Application Automation.

A helps with identifying the file, and B helps with opening a workbook file (GetObject()).

Plase also check out Before Posting (VBA or SQL) Code.
Feb 7 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
976
by: Andre | last post by:
Hi, I'm using a PCOMM AutSess instantiated class to establish a session with an IBM host (S/390) from within an Excel spreadsheet using: session.SetConnectionByName Not sure how long this...
18
8268
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a...
6
8689
by: cyberco | last post by:
Using fileinput.input('test.txt') I probably forgot to process all lines or so, since I get the error 'input() already active' when i try to call fileinput.input('test.txt') again. But how can I...
0
912
by: Meera | last post by:
I use VS 2005.I wanted to write a macro for generating comments which is on the form //<Code Review Comments> //<summary> //ClassName : Program //Function Name : Main //Line Number : 18...
2
3732
by: socialmx | last post by:
Hi dear friends. Can anyone help me? I created a VB form in Excel and a textbox and one command button. When I click the command button the text entered in the textbox will store in the empty cell...
6
3683
by: bill | last post by:
I have been "Googling" for about an hour and am turning up squat! I just started receiving this error when trying to log into a MS Access database from a vb .net web application. Recycling IIS...
3
13068
by: FeelLikeANut | last post by:
I have the code below. First there is a transaction where I select data. I wrapped it in an explicit transaction because in my real program I run a couple different selects. Nevertheless, the...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.