Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Need macro to insert workbook into another workbook using input box

I am new to programming in Excel with VBA and I have spent 4 hours searching
the archives for a solution to my challenge.

I am developing a simple application for other users who may or may not have
a lot of computer knowledge. I am making it as user-friendly as possible with
user forms and locking areas of the workbook they shouldn't mess with.

The procedure the users will follow:
1. Open 'my workbook' [which contains all of the macros needed for the rest
of the operation]
2. Autostart an 'input box' which will allow them to select a file [could be
in .xls or .csv format- the file is unique to their location] which will
import the 'worksheet' into 'my workbook' as the last worksheet.
3. Use further userform-based macros to chart their 'worksheet' data.
4. The added 'worksheet' must be deleted automatically when 'my workbook'
closes.

Can anyone suggest a macro [step 2] for choosing, opening and inserting the
unique file and another [step 4] that would delete the worksheet upon closing?


Any help would be appreciated.

Thanks,
Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Need macro to insert workbook into another workbook using input box

Deleting a worksheet when the workbook closes is a problem. If the user doesn't
save, then the the sheet isn't deleted. To make that automatic seems like more
of problem to me. If the user opens excel and closes and doesn't want to save,
should you force him/her.

How about just deleting the sheet when the code starts?

Something like:

Option Explicit
Sub testme()

Dim wkbk As Workbook
Dim tempWks As Worksheet
Dim myFileName As Variant

myFileName = Application.GetOpenFilename("Excel files, *.xls;*.csv")
If myFileName = False Then
Exit Sub
End If

Set wkbk = Workbooks.Open(Filename:=myFileName)

On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("TempSheet").Delete
Application.DisplayAlerts = True
On Error GoTo 0

wkbk.Worksheets(1).Copy _
after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)

Set tempWks = ActiveSheet
tempWks.Name = "TempSheet"

'your code here.

End Sub


newnhamm wrote:

I am new to programming in Excel with VBA and I have spent 4 hours searching
the archives for a solution to my challenge.

I am developing a simple application for other users who may or may not have
a lot of computer knowledge. I am making it as user-friendly as possible with
user forms and locking areas of the workbook they shouldn't mess with.

The procedure the users will follow:
1. Open 'my workbook' [which contains all of the macros needed for the rest
of the operation]
2. Autostart an 'input box' which will allow them to select a file [could be
in .xls or .csv format- the file is unique to their location] which will
import the 'worksheet' into 'my workbook' as the last worksheet.
3. Use further userform-based macros to chart their 'worksheet' data.
4. The added 'worksheet' must be deleted automatically when 'my workbook'
closes.

Can anyone suggest a macro [step 2] for choosing, opening and inserting the
unique file and another [step 4] that would delete the worksheet upon closing?

Any help would be appreciated.

Thanks,
Mike


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Need macro to insert workbook into another workbook using input box

Dave, opening and inserting the sheet works beautifully!

Deleting the sheet when the code starts is an elegant workaround!

Many thanks, you have helped immensely!

Mike

Dave Peterson wrote:
Deleting a worksheet when the workbook closes is a problem. If the user doesn't
save, then the the sheet isn't deleted. To make that automatic seems like more
of problem to me. If the user opens excel and closes and doesn't want to save,
should you force him/her.

How about just deleting the sheet when the code starts?

Something like:

Option Explicit
Sub testme()

Dim wkbk As Workbook
Dim tempWks As Worksheet
Dim myFileName As Variant

myFileName = Application.GetOpenFilename("Excel files, *.xls;*.csv")
If myFileName = False Then
Exit Sub
End If

Set wkbk = Workbooks.Open(Filename:=myFileName)

On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("TempSheet").Delete
Application.DisplayAlerts = True
On Error GoTo 0

wkbk.Worksheets(1).Copy _
after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)

Set tempWks = ActiveSheet
tempWks.Name = "TempSheet"

'your code here.

End Sub

I am new to programming in Excel with VBA and I have spent 4 hours searching
the archives for a solution to my challenge.

[quoted text clipped - 20 lines]
Thanks,
Mike


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
Macro or OLE method to insert worksheet from template workbook Lyndon Rickards Excel Discussion (Misc queries) 0 January 30th 06 08:46 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Excel Programming 9 July 25th 05 12:44 PM
Insert VBA code with a macro in a .xls file by workbook open event mihai[_3_] Excel Programming 8 July 29th 04 01:49 PM
Excel Gurus = want a macro in 1 workbook to get info from another workbook = Read please harry Excel Programming 5 December 20th 03 03:26 AM
insert macro in new workbook Douvid[_2_] Excel Programming 1 July 29th 03 04:19 PM


All times are GMT +1. The time now is 10:53 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"