Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 50112 articles
Browse latest View live

Output redirection from BAT or VBS to text file.

$
0
0
Hello again forum,

I am working on a VBA routine that calc and verifies hash files for a series of folders and sub directories, using a command line prog called exactfile.exe (exactfile.com). It is very similar to M$'s FCIV utility, but it is actually supported on Win7/Win8. The issue I am having is that I cannot get the standard output/error/console stream to redirect to a text file. I've written the routine multiple ways, trying to figure out redirection. I was using this site
HTML Code:

http://www.robvanderwoude.com/battech_redirection.php
as a reference.

Here is my VBS approach. This code is dependent on another sub passing folder_name as a string

Code:

Dim sFSpec As String: sFSpec = "C:\exf\verify_files.vbs"
Dim sParams As String: sParams = "" & folder_name ' this is passed from another sub routine
Dim sCmd As String: sCmd = """" & sFSpec & """ " & sParams
Dim oWSH: Set oWSH = CreateObject("WScript.Shell")
oWSH.Run sCmd, 1, True

The VBS then executes using wscript, however, since exf.exe does not return an exit code the same way FCIV.exe does, I need the results redirected to a text file. The results vary from a single line saying "No errors." or multiple lines indicating which files do not match their original hash.

Here are a couple iterations of my BAT approach, where i use the BAT to call the VBS. I really thought I would be able to use the standard redirect > here, since the executable is launched using cmd.exe, but I've not gotten the results I want.

Code:

retval = Shell("C:\exf\testing\verify_files.bat " & fldr_name & ">test.txt 2>&1", vbMinimizedFocus)
retval = Shell("C:\exf\testing\verify_files.bat " & fldr_name, vbMinimizedFocus)

I've scoured more pages than I can count, but no approach seems to work, so far. I would appreciate a second or third set of eyes looking at this with me

Thanks!

WH

HELP! Transferring Rows of Multiple Data Between Workbooks

$
0
0
Hi,

I have two workbooks with similar columns (note: both workbooks may not have all the same columns, but for the same columns, the names are written identically in both workbooks). I'll walk through what's in each sample workbook I've provided and what I am hoping to accomplish.

Transfer Rows1: This workbook contains multiple rows of data for one company or ID (For example, Client "A Co" has 4 rows of data.)

Transfer Rows2: Contains some of the same columns as workbook 1, but not exactly in the same order.

What I want to do is take all the multiple row data for an ID in Transfer Rows1 and put the information as a single row in Transfer Rows2. So, Client "A Co" in Workbook 1 has 4 rows, but in Workbook 2 will have 1 row. It's matching columns, essentially. Columns that are present in both workbooks should have the data filled out in only ONE row in Transfer Rows2.

As far as cost is concerned, Cost A in Transfer Rows2 is just the sum of all the Cost A's for a particular ID Number in Transfer Rows1 (same for Cost B and Cost C).

I also want the installation date in Transfer Rows2 to be the latest installation date for each unique ID from Transfer Rows1.

Also, a particular client can have multiple CID's. This appears in different rows in Transfer Rows1, but should appear in one row, multiple columns (again, for each unique ID) in Transfer Rows2.

Notice, the column 'Products' in Workbook 1 is not in Workbook 2, and that's because each row for column may have different information and thus I would not be able to transfer it into a single row in workbook 2.

TransferRows1 is where I am right now and I have filled out TransferRows2 to indicate what I hope to accomplish. I am posting here because the actual set I am working is fairly large, on the order of ~ 35,000 rows and need to automate this process using code instead having to copy and paste thousands of times. Sadly, I am not very good at VBA, and that's why I need help!

I've posted about this problem before, but I incorrectly forgot to put in a few things that also needed to be done, and there are some changes, hence I'm posting again.

Any help would be very glady appreciated!

Track Computer Lock and Unlock time in excel

$
0
0
Hi
I want to make break tracker. When i press Windows + L Or CTRL + ALT + DELETE (Lock computer) Automatically lock time upload in my excel sheet. Then when i unlock pc then automatically unlock time will upload in my excel sheet.

Kindly Help.

Thanks
Subir Basak

[SOLVED] BeforeClose event not running/working when file is closed through VBA in another file

$
0
0
I have a code in file A that opens several files (B,C,D&E), copies some data from them, then closes the files.
That part of the code works fine, but each of the files that are opened (B,C,D,&E) have a Workbook Open event that causes the file to save automatically every 30 seconds. (I know this is not recommended, but this is what the user wants.) The files also have a Workbook Before Close event that is supposed to stop the timer so the file will close without reopening. These each run fine on their own.
But if I run code A, the workbook Before Close event in file B (C,D, & E) does not seem to run and the files reopen after 30 seconds to save. When I step through the code it works fine and goes through the Before Close event in each file and the files remain closed.

I feel like there is something obvious I am missing. Any help is greatly appreciated. Thanks for taking the time to read my post.

File A code:
Code:

Sub CreateMasterLog()
MSG1 = MsgBox("This will clear the current Pathology Log and replace it with the data on the current provider files.", vbYesNo, "Are you sure you want to continue?")
If MSG1 = vbYes Then

Sheets("Pathology Log").Range("A2:M2").End(xlDown).ClearContents
Dim v As Workbook
Dim w As Workbook
Dim x As Workbook
Dim y As Workbook
Dim z As Workbook
Dim varCellvalue As String
Dim varCellvalue2 As String
Dim varCellvalue3 As String
Dim varCellvalue4 As String
Dim varFilevalue As String
Application.ScreenUpdating = False
varFilevalue = Sheets("File Locations").Range("B2").Value
varCellvalue = Sheets("File Locations").Range("B3").Value
varCellvalue2 = Sheets("File Locations").Range("B4").Value
varCellvalue3 = Sheets("File Locations").Range("B5").Value
varCellvalue4 = Sheets("File Locations").Range("B6").Value

'## Open all workbooks first:
Set v = Workbooks.Open(varFilevalue & varCellvalue4)
Set w = Workbooks.Open(varFilevalue & varCellvalue3)
Set x = Workbooks.Open(varFilevalue & varCellvalue)
Set y = ThisWorkbook
Set z = Workbooks.Open(varFilevalue & varCellvalue2)

'Now, copy what you want from x: and paste to y:
Dim LastRow2 As Long
LastRow2 = x.Worksheets("Pathology Log").UsedRange.Rows.Count
Dim LastRow3 As Long
LastRow3 = w.Worksheets("Pathology Log").UsedRange.Rows.Count
Dim LastRow4 As Long
LastRow4 = v.Worksheets("Pathology Log").UsedRange.Rows.Count
Dim LastRow5 As Long
LastRow5 = z.Worksheets("Pathology Log").UsedRange.Rows.Count

x.Sheets("Pathology Log").Range("A2:M" & LastRow2).Copy
y.Sheets("Pathology Log").Range("A2").PasteSpecial
Application.CutCopyMode = False
z.Sheets("Pathology Log").Range("A2:M" & LastRow5).Copy
y.Sheets("Pathology Log").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
w.Sheets("Pathology Log").Range("A2:M" & LastRow3).Copy
y.Sheets("Pathology Log").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
v.Sheets("Pathology Log").Range("A2:M" & LastRow4).Copy
y.Sheets("Pathology Log").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False

'Close x & z:

x.Close
z.Close
w.Close
v.Close

y.Sheets("Filter").Select

End If
End Sub

File B, C, D, & E code posted in ThisWorkbook:
Code:

Private Sub Workbook_Open()
    Call StartTimer
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call StopTimer
End Sub

File B, C, D, & E code posted in Module:
Code:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30 ' 30 seconds
Public Const cRunWhat = "TheSub"  ' the name of the procedure to run

Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=True
End Sub

Sub TheSub()
    ThisWorkbook.Save
    StartTimer  ' Reschedule the procedure
End Sub

Sub StopTimer()
    On Error Resume Next
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=False
End Sub

Hide a Row Based on a Cells Value

$
0
0
I am very very new to VB but i'm in need of code that will automatically hide a row based on its value in Column A. My range in column A is A22:A37. If the value in A22 is "0" I would like to hide row 22 all together. The values in A21:A35 are populated by a formula referencing data in another worksheet. I figure this shouldn't be to hard but it's above my knowledge base.

Many Thanks ahead of time!

VBA - Internet Explorer find value within webpage

$
0
0
Hey Guys,

I'm intermediate at VBA and VERY new to vba/internet explorer interaction. I've been having some luck logging on and taking values from websites by looking at their source code but Im having trouble grabbing some data that isn't tagged as clearly as others ive seen, here's the html of the table below, this table is pretty similar across the many webpages I plan to look at.
Code:

<table ALIGN="center" border="0" CELLSPACING="1" CELLPADDING="1">

<tr>
          <td><font face="Arial" size="1">Time</font></td>
          <td><font face="Arial" size="1">Amount</font></td>
          <td><font face="Arial" size="1">Range</font></td>
        </tr>
     
      <tr>
        <td><input readonly value="10437-15093" size=16></td>
        <td><textarea readonly rows="2" cols="60">9,113,560</textarea></td>
        <td><input readonly value="" size=22 maxlength=32></td>
      </tr>
</table>

I'm trying to select the data that I put in bold. Since they don't have a name I can try to loop to find I tried to find them by using their attributes (rows and cols sizes) which are unique to the page and each page like this. The code I tried to use but that doesn't catch it (the loop continues past the XXXX i guess) is below
Code:


Sub quicktest()

Dim HyperLink1 As String
Dim IE As Object
Dim objE As Object
Dim objC As Object
Dim objc2 As Object

Set IE = CreateObject("InternetExplorer.Application")
Dim sURL As String, Pass As String, name As String, X As String, Y As String

 HyperLink1 = ActiveCell.Hyperlinks(1).name
'MsgBox (HyperLink1)

With IE
.navigate HyperLink1
.Visible = True
End With
Set objC = IE.document.getElementsByTagName("input")
 i = 0
  While i < objC.Length
        If objC(i).Size = 16 Then
 
            ' Set text for search
          If objC(i).name <> "dateDrillingCommenced" Then
            Y = objC(i).Value
            MsgBox (Y)
           
            End If
            End If
        If objC(i).Value <> "" Then GoTo Step3
        i = i + 1
  Wend
Step3:
  Set objC = IE.document.getElementsByTagName("textarea")
 i = 0
  While i < objC.Length
        If objC(i).Rows = "16" Then
 
            ' Set text for search
          If objC(i).cols = "60" Then
            X = objC(i).textarea
            MsgBox (X)
           
            End If
            End If
     
        i = i + 1
  Wend

Everything works until this point any thoughts? Using a Querytable pull identifies this table as .WebTables = "20" fyi.

Thanks in advance guys.

How to assign a number to course name in inputbox

$
0
0
Hi friends,
In column ‘o’ I have inserted a number for course name in column ‘p’. I want to assign a course name to that particular number as follows:

Column ‘o’ Number ... Column ‘p’ Course name
1: A. B. C.
2: J. K. L.
3: P. Q. R.
4: X. Y. Z.

And so on as per course names.

If I enter number 1 in inputbox then I want to enter the course name in column ‘b4’ respectively.

Code:

Sub StudentList()

Dim y As String
Dim c As String

    y = InputBox("enter academic year to filter")
    c = InputBox("enter course number to filter")
 
        Application.EnableEvents = False
       
    Range("n7").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$7:$aa$3000").AutoFilter Field:=13, Criteria1:=y, Operator:=xlAnd
    Range("o7").Select
    ActiveSheet.Range("$B$7:$aa$3000").AutoFilter Field:=14, Criteria1:=c, Operator:=xlAnd
Range("b4") = y & " " & c

        Application.EnableEvents = true


End sub

Any help will be appreciated.

Thanking you.

Mukesh

sending image or range as body via CDO

$
0
0
Hi guys, this must be a frequent question and ive run through Ron De Burin's manuals but i cant seem to get this to work, ive had it work before but its just not working!!!!

I need to either send a range, or a image as the body.. here is current script. - Im happy to send body with range.. or chart exported to an image..

Code:

Sub CDO_Send_Selection_Or_Range_Body()
    Dim rng As Range
    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

        iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserver"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With


    Set rng = Worksheets("temp").Range("a1:h9")
    On Error Resume Next

    Set rng = Selection.SpecialCells(xlCellTypeVisible)

    On Error GoTo 0

    If rng Is Nothing Then
        MsgBox "The selection is not a range or the sheet is protected" & _
              vbNewLine & "please correct and try again.", vbOKOnly
        Exit Sub
    End If

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    With iMsg
        Set .Configuration = iConf
        .To = "thomas_webb@flightcentre.com"
        .CC = ""
        .BCC = ""
        .From = """Ron"" <thomas_webb@flightcentre.com>"
        .Subject = "This is a test"
        .HTMLBody = RangetoHTML(rng)
        .Send
    End With

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub


Copy Cells from one workbook to another

$
0
0
Hello,

I recorded a macro to copy and paste values from several different ranges in one workbook, then open a destination workbook and paste them there. For the most part it just goes back and forth till it's done. It works just fine but I was wondering if there was a more efficient way of doing this? Maybe with the use of an Aeeay Thank you in advance for looking at my code. :)


Code:

Worksheets("ECN_Form").Activate
    Worksheets("ECN_Form").Range("AA1").Select
    Selection.Copy
    ChDir "\\psf\Home\Desktop\TestEnviroment\"
    Workbooks.Open Filename:="\\psf\Home\Desktop\TestEnviroment\LogTest.xlsm"
    Range("A:A").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
       
    Worksheets("ECN_Form").Range("R5").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("B2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    Worksheets("ECN_Form").Range("F5").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("C2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    With myClipbd
        .SetText Me.Controls.Item("TxtFromToSum").Text
        .PutInClipboard
    End With
    Windows("LogTest.xlsm").Activate
    Range("D2").End(xlDown).Offset(1, 0).Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
        False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    Worksheets("ECN_Form").Range("A10").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("E2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    Worksheets("ECN_Form").Range("K11").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("F2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    Worksheets("ECN_Form").Range("F3").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("G2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    Worksheets("ECN_Form").Range("S36").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("I2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
   
    Worksheets("ECN_Form").Range("R3").Select
    Selection.Copy
    Windows("LogTest.xlsm").Activate
    Range("J2").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    Range("H2").End(xlDown).Offset(1, 0).Value = "PENDING"
   
    Range("A1").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Save
    ActiveWindow.Close
       
    Worksheets("ECN_Form").Visible = False
   
    'Open_F = Application.GetOpenFilename()

    Application.ScreenUpdating = True
    UserForm1.Hide
    Application.Visible = True
    Application.DisplayAlerts = False
    ThisWorkbook.Close

vba to copy and insert row and copy/paste cell value if cell not blank!

$
0
0
Hi
I'm using xl2010. In the example, I want to split a sku code into two lines:-
If column D has text, copy that row and insert into next row; then copy the value from column D in original row to column C in new row and copy columns E:F in original row to A:B in new row.

This seems very complicated and I can't figure it out. I'm relatively new to vba and rely on these excellent forums to learn and try solutions.

I'd really appreciate any suggestions and help.
Many thanks
Gary

xlsexample.png
Attached Images

Simplify VBA code to go to Specific cells in different worksheets

$
0
0
Hi,

can anyone help me why I cant simplify this code to go to specific cells if the we are in different worksheets

e.g. ActiveSheet at "Sheet2"

Code:

Worksheets("Sheet1").Select
Range("A1").Select


Error to use this;
Code:

Worksheets("Sheet1").Range("A1").Select

How do you get a cell to be Tuesday-Thursday?

$
0
0
I am trying to use configure a code similar to this... =IF(TEXT(A1-1,"dddd")="Friday",A1-1,IF(TEXT(A1-2,"dddd")="Friday",A1-2,IF(TEXT(A1-3,"dddd")="Friday",A1-3,IF(TEXT(A1-4,"dddd")="Friday",A1-4,IF(TEXT(A1-5,"dddd")="Friday",A1-5,IF(TEXT(A1-6,"dddd")="Friday",A1-6))))))
but to identify the date closest that is not a Monday, Tuesday or Friday.

For example...
The attached sheet cell C33. See comments.
Attached Files

Macro that saves a copy of document in a different folder location

$
0
0
I have attached my workbook. I am trying to use this macro to copy and paste a document from one location to another.
I keep getting run-time error '52' "Bad file name or number".
I know the file location that I am referencing is correct but it does not seem to be working.
Can anyone help me with this?
Thanks,
Attached Files

dropdown list using filters

$
0
0
Hi everyone,

Thanks for taking the time to read this post, in short I am still working on a project tracking results. My main problem lies in the fact I have a main dropdown box in cell O5 regarding classes, other measures in cell Q5 which are also needed. I wish to have my main array of results change with whatever class is in cell O5, also could it be possible to change my array with what is also in cell Q5.

The only way I have managed so far is by doing filtering, vlookup and countifs but this is too long..i think this can be done in VBA Excel. Moreover if you double click on a cell that has a value of 1 or more then it will reveal the names of the individual.

I would be grateful for any advice or hep given.
Thank you again for taking the time to read this message.
Attached Files

deleting picture (shape)

$
0
0
Hello Gurus,

The user of this spreadsheet inserts data and pastes a picture in the a specific place. Example cell AJ4

Sometimes the user copies the spreadsheet and deletes the picture and adds another.

I am looking to create a macro that deletes the picture automatically (and perform some other functions).

Below is the recorded code for deleting that picture in the spreadsheet. However, the name "Picture 2" is constantly changing, therefore the code cannot specifically say "picture 2"


Code:

ActiveSheet.Shapes.Range(Array("Picture 2")).Select
    Selection.Delete

How do I get around this?

TIA,
Tim

Reset variables for each pass through a For loop

$
0
0
I am having trouble defining a variable in a For loop. When I run the loop the first time everything seems to work fine, but when the loop goes back through the second time it carries its previous value with it. Here in lies the problem if the variable is supposed to be empty (not assigned a value). So, for example: 'Variable' in the code below may or may not be given a value depending on the conditions in the For i loop. If it is given a value then 'Variable' will still have that value on the next pass through the For j loop. And if none of the conditions are met for the If statement in the For i loop the second time through the For j loop, it should be an empty variable, but instead the code is reading it as having a value (from the previous pass through the For j loop).

Code:

For j = 0 To 11
  'do stuff
    For i = 1 To 10
      If 'stuff' Then
        Variable = 'something
        Exit For
      End If
    Next i
  If IsEmpty(Variable) Then
    'do stuff
  Else
    'do stuff
  End If
Next j

I have tried using
Code:

Set Variable = Nothing
after the For j line, and instead of using
Code:

If IsEmpty(Variable) Then
I tried using
Code:

If Variable is Nothing Then
and I've tried
Code:

If Not Variable is Nothing Then
.
I get an Object error with either line I use. I just want to be able to reset the variables each time through the For j loop so in the case of an empty variable, it doesn't try to calculate based on the previous value.

Any help on the issue will be greatly appreciated.

copy only visible text boxes to clipboard from user form

$
0
0
hi all

i have been stuck on this for a while now. i have created a command button that copies a string to clip board. this strings is made up of text boxes on a user form. the text boxes are filled in by the user but depending on the users input some remain hidden. when i copy to clip board the hidden text boxes leave blank gaps . is there any way to get these removed so when pasted the hidden text boxes dont leave a gap. Heres my code. thank you so much in advance for your help

Code:


Dim DataObj As New MSForms.DataObject
    Dim STR1 As String
   
  STR1 = A0 + vbCrLf + vbCrLf + A49 + "    " + A50 + vbCrLf + A46 + "    " + A47 + vbCrLf + A1 + "    " + A2 + vbCrLf + vbCrLf + A3 + "    " + A4 + ComboBox3 + vbCrLf + vbCrLf + A5 + "    " + A6 + vbCrLf + A7 + "    " + A8 + vbCrLf + A9 + "    " + A10 + vbCrLf + vbCrLf + A11 + "    " + A12 + ComboBox4 + vbCrLf + A13 + "    " + A14 + vbCrLf + A15 + "    " + A16 + vbCrLf + A17 + vbCrLf + A18 + vbCrLf + vbCrLf + A19 + "    " + A20 + vbCrLf + A21 + "    " + A22 + vbCrLf + A23 + "    " + A24 + vbCrLf + A25 + "    " + A26 + vbCrLf + A27 + "    " + A28 + vbCrLf + vbCrLf + A29 + "    " + A30 + vbCrLf + A31 + "    " + A32 + vbCrLf + A33 + "    " + A34 + vbCrLf + A35 + "    " + A36 + vbCrLf + A37 + "    " + A38 + vbCrLf + vbCrLf + A39 + vbCrLf + A40 + vbCrLf + A48 + vbCrLf + vbCrLf + A41 + vbCrLf + vbCrLf + A42 + "    " + A43 + vbCrLf + A44 + "    " + A45
   

 
 
 
    With DataObj
 
 
        .SetText STR1.Value
       
       
        .PutInClipboard
       
   
        Unload UserForm10
   
     
  MsgBox "Notepad copied to clip board"
     
      End With




End Sub

Set Button as ActiveCell

$
0
0
Hi all,

After having been helped at one part of my project, I am now stuck at another one. Please have a look at the attachment (I have tried to keep it as simple as possible by removing everything not related). "Button1" triggers the creation of the buttons

The final file will contain an unknown amount of rows/columns, with, as header, ID / TEXT1 / TEXT2 / TEXT... (Around 300k cells total)
The final user will have to count how many words are in the cells of a specific column (he may need to do it for other columns as well).

My approach is the following:

1-Find the header, and convert each of its cells into individual buttons (one per column, each button automatically fitting in the cell)
Sub Create_Buttons()
-->Done, an issue may exist

2- When the user click on one of these buttons, a column is added on the right, each cell being filled up with the number of words in the cell on the right (thank you for the previous help)
Sub WordsPerCell_Button()
-->Partially done

Problem:

When I click on a "TEXT..." button, I expected this button to become the ActiveCell, so that:
- the length of the column would be measured (no empty cell)
- the rank of the column would be picked up before inserting a column to its right

Now, it is not working this way. ActiveCell is actually the one selected before clicking on the button.
I've found on the forum and the help several references to SetFocus and TakeFocusOnClick, but I have not been able to use them properly so that the ActiveCell will be the one with the button.

Any help would be very much appreciated.
Thank you.
WordsPerCell.xlsm

Macro to Combine Multiple Workbook Data into Single Target Workbook

$
0
0
Hi,

I have the following code that I used for a prior project using Excel 2003 and its related libraries. The code was used to pull data from a folder full of excel files that all had the same single page layout but different data and combine the data in a single target-workbook.

I am now trying to use the same code with Excel 2010 to go through a folder of new excel files that have a different layout than in the prior project. With the new files (see attached example) I want to copy the source data from the "Enter Data Here" sheet and add it to the destination workbook that is running the macro. (Please note that the "Enter Data Here" is not always consistently the same sheet number from one file to the next, so we would need to reference the sheet name and not the number.)

- I was planning to have the destination workbook receive the combined data on the sheet called "Pasteit".

When I run the code in Excel 2010, it opens the first file and then hangs on line 28. I feel like I'm missing something obvious.... your advice would be greatly appreciated!

Code:

Sub CombineSourceFiles()

  Dim DstRng As Range
  Dim DstLastRow As Long
  Dim FileFilter As String
  Dim SrcLastRow As Long
  Dim SrcRng As Range
  Dim Sourcefile As String
  Dim ofs As New FileSystemObject
  Dim strFolder As String
  Dim oFile As Object
  Dim oFolder As Object
  Dim wrkInput As Workbook
  Dim wrkOutput As Workbook
 
  Set wrkOutput = ThisWorkbook
 
  'Set input folder path here, change to D
  strFolder = "D:\My Documents\B\PROJECTS\Printer REFRESH\CutSheets\Process"
 
  Set oFolder = ofs.GetFolder(strFolder)
 
  For Each oFile In oFolder.Files
    Set wrkInput = Application.Workbooks.Open(strFolder & "\" & oFile.Name)
       
        With wrkOutput.Worksheets("Pasteit")
          DstLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
          Set DstRng = .Range(.Cells(3, "A"), .Cells(DstLastRow, "K"))
        End With
       
        Set SrcWkb = wrkInput
       
          With SrcWkb.Worksheets("Enter Data Here")
            SrcLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
            Set SrcRng = .Range(.Cells(3, "A"), .Cells(SrcLastRow, "K"))
          End With
         
          SrcRng.Copy Destination:=DstRng.Cells(DstLastRow, "A")
                   
      Application.CutCopyMode = False
     
    SrcWkb.Close
    Next
   
End Sub

Attached Files

Call UserForm from a variable number of ActiveX command buttons

$
0
0
I want to be able to call one user form from multiple ActiveX command buttons. The problem is, the number of command buttons depends on user input on another worksheet, so it's variable.

I've renamed all of the command buttons so they are named "CommandButton" & i, where i is an integer between 1 and, say, 200. I want each of these buttons to direct to the same UserForm where additional information can be entered.

I can't think of a way around the event-handler procedure name.

Sub [Command Button Name]_Click

to call the User Form. I won't know the command button names, because I won't know how many there are (max i) until the user inputs.

Basically, I want to create a For loop through the max i and have the event-handlers call the user form

Any ideas?
Viewing all 50112 articles
Browse latest View live