Lost in Strings-When running macro another Excel workbook is opened

Lacampeona

New Member
Joined
Mar 31, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hello experts
I am new in writing my own procedures so yesterday and today I have some problems with excel.

I am lost in strings. I tried everything I dont know what I am doing wrong! Helpppp meee!!

I have a code written and saved under module in lets say Excel tblDsd.xlsm. That macro I convert in "Smile Face" in ribbon tab. When I am working with Excel tblSp.xlsm and I click the "Smiley face" to run my macro, everytime again and again the workbook A is also opening.
My question? why?
Where I should paste my procedure for macro for smiley face?
A) Modul
B) Worksheet
C) Workbook

Here is the code foy my "Smiley Face":

1711981136699.png


1711981100044.png


Sub ImportDatafromotherworksheet()
Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set wkbSourceBook = ActiveWorkbook
Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8)
wkbCrntWorkBook.Activate
Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
wkbSourceBook.Close False
End If
End With
End Sub


Thanks in advance experts
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I write some mistake in naming my file
Wrong:
When I am working with Excel tblSp.xlsm and I click the "Smiley face" to run my macro, everytime again and again the workbook A is also opening.

Correct:
When I am working with Excel tblSp.xlsm and I click the "Smiley face" to run my macro, everytime again and again the workbook tblDsd.xlsm is also opening.
 
Upvote 0

Forum statistics

Threads
1,215,205
Messages
6,123,632
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top