Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default export sheet

Hi all

I need a simple macro to export one worksheet to a existing workbook.
the name of the worksheet must be entered in a msgbox

Can anybody help me ?







  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default export sheet

Hi,
Try something like the following (modify code to fit your scenario in
section 'Change Here'):
Sub Macro2()

Dim wshO As Worksheet, nameO As String 'Origin sheet
Dim wshD As Worksheet, WbkD As Workbook, nameD As String 'Destination
variables
Dim count As Long


' Set variables
'------ CHANGE HERE ------------
Set wshO = ActiveSheet
Set WbkD = Workbooks(2)
'-------------------------------
nameO = wshO.Name
count = WbkD.Sheets.count

'Get name from user
nameD = Application.InputBox("Enter new name", "New Sheet Name")
If nameD = "False" Then Exit Sub 'Cancelled by user

'Copy sheet
wshO.Copy After:=Workbooks(2).Sheets(count)
Set wshD = WbkD.Sheets(count + 1) 'new sheet is last one

'Rename
On Error Resume Next
wshD.Name = nameD
If Err < 0 Then
MsgBox "The provided name '" & nameD & "' is not valie (invalid or
already exist)" & _
vbNewLine & "Please, set it manually."
End If
End Sub

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"christophe" wrote:

Hi all

I need a simple macro to export one worksheet to a existing workbook.
the name of the worksheet must be entered in a msgbox

Can anybody help me ?







  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default export sheet

thanks , it works just perfect

"sebastienm" wrote:

Hi,
Try something like the following (modify code to fit your scenario in
section 'Change Here'):
Sub Macro2()

Dim wshO As Worksheet, nameO As String 'Origin sheet
Dim wshD As Worksheet, WbkD As Workbook, nameD As String 'Destination
variables
Dim count As Long


' Set variables
'------ CHANGE HERE ------------
Set wshO = ActiveSheet
Set WbkD = Workbooks(2)
'-------------------------------
nameO = wshO.Name
count = WbkD.Sheets.count

'Get name from user
nameD = Application.InputBox("Enter new name", "New Sheet Name")
If nameD = "False" Then Exit Sub 'Cancelled by user

'Copy sheet
wshO.Copy After:=Workbooks(2).Sheets(count)
Set wshD = WbkD.Sheets(count + 1) 'new sheet is last one

'Rename
On Error Resume Next
wshD.Name = nameD
If Err < 0 Then
MsgBox "The provided name '" & nameD & "' is not valie (invalid or
already exist)" & _
vbNewLine & "Please, set it manually."
End If
End Sub

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"christophe" wrote:

Hi all

I need a simple macro to export one worksheet to a existing workbook.
the name of the worksheet must be entered in a msgbox

Can anybody help me ?







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
Export sheet VLOOKUP fORMULA Excel Discussion (Misc queries) 1 March 28th 09 11:45 PM
Export Data into another sheet Kenny Excel Discussion (Misc queries) 0 October 1st 07 09:47 AM
export excel data to another sheet owl527[_19_] Excel Programming 3 January 10th 06 11:22 AM
Export Excel Sheet to JPG or TIF quartz[_2_] Excel Programming 3 January 7th 05 09:41 PM
Export just one sheet from a workbook Grek[_3_] Excel Programming 2 May 9th 04 01:52 PM


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