Over 1 million tech questions and answers.

Need VBA Word and VBA Excel Code Samples

Q: Need VBA Word and VBA Excel Code Samples

Do any of you know where I can find an excellent and massive code sample database on the web? Need samples for Word and Excel.

Many sites have a few samples but I need a database of samples to re-learn what I have forgotten.

RELEVANCY SCORE 200
Preferred Solution: Need VBA Word and VBA Excel Code Samples

I recommend downloading and running Reimage. It's a computer repair tool that has been proven to identify and fix many Windows problems with a high level of success.

I've used it in the past to identify and fix everything from blue screens (BSOD's), ActiveX errors, corrupt files and processes, dll/exe/sys errors, recover lost memory, Windows update problems, defragging, malware removal etc.

You can download it direct from this link http://downloadreimage.com/download.php. (This link will automatically start a download of Reimage that you can save to your computer.)

A: Need VBA Word and VBA Excel Code Samples

Have you taken a look at www.vbaexpress.com? The site is dedicated to VBA and contains a good knowledgebase. The regulars there are also very willing to answer your questions and help develop/refine you code.

James

Read other 2 answers
RELEVANCY SCORE 61.6

Hiya

ListBox and ComboBox

This sample demonstrates several different techniques for binding data to ListBox and ComboBox controls, and shows different ways to retrieve the selected item or items from the controls.
System Requirements
Supported Operating Systems: Windows 2000, Windows NT, Windows XP

- Microsoft Visual Studio. NET Professional
- Access to the Northwind database residing in SQL Server or the Microsoft Data Engine (MSDE)
http://www.microsoft.com/downloads/...b6-a75d-45a3-8200-7f5e396558ed&DisplayLang=en

XP Theme Support

This sample demonstrates how to enable support for XP themes in your application
System Requirements
Supported Operating Systems: Windows 2000, Windows NT, Windows XP

- Microsoft Visual Studio. NET Professional

http://www.microsoft.com/downloads/...8f-bad3-4b37-a99d-be48f6fb3913&DisplayLang=en

Automate Office

This application has three demonstrations involving the following Office components: Microsoft Agent, Microsoft Word, and Microsoft Excel. When referencing the various COM Office assemblies, Visual Studio .NET automatically creates COM runtime callable wrappers (RCW) so you can program against them from within .NET.

System Requirements
Supported Operating Systems: Windows 2000, Windows NT, Windows XP

- Microsoft Visual Studio. NET Professional or greater

http://www.microsoft.com/downloads/...31-d4c4-4716-abd6-74a11bb85c9f&DisplayLang=en

Send and Receive Data

This solution demonstrates how to send and receive da... Read more

Read other answers
RELEVANCY SCORE 61.2

Hiya

This sample illustrates how to create custom owner-drawn menu items

System Requirements

- Microsoft Visual Studio. NET Professional

Operating System - Windows NT 4.0 & 2000, Win XP

http://www.microsoft.com/downloads/release.asp?ReleaseID=40929&area=search&ordinal=25

This download represents a master set of Visual Basic .NET code samples demonstrating various aspects of the language in the following areas: syntax, data access, Windows Forms, Web development and Web services, XML, security, the .NET Framework, file system and file I/O, interop and migration issues, COM+, ADO.NET, and advanced topics including graphics with GDI+, remoting, serialization, MSMQ, and Windows services.

System Requirements

- Microsoft Visual Studio. NET Professional

Note: some samples also require access to the Northwind database residing in SQL Server or the Microsoft Data Engine (MSDE)

Operating System - Windows NT 4.0 & 2000, Win XP

http://www.microsoft.com/downloads/release.asp?ReleaseID=41079&area=search&ordinal=22

Regards

eddie
 

Read other answers
RELEVANCY SCORE 58.4

Hi,
We have a performance monitor application that creates CSV files. This was part of a legacy design and changing the CSV to BLG will break many of the other dependent tools in the application. To assist the other teams in viewing the data as one single file,
we decided to use Relog to convert each CSV to corresponding BLG and join all the blg's to one single blg file.
however, while doing the second step I keep getting this error message 
"At least one of the input binary log files contain fewer than two data samples."
Two questions:
1. How can I resolve this problem. The solutions that are provided in the blogs ask to change the account type to "Remote" from "System" but that does not seem to relate to my problem. My problem is merging all the BLG files to one single
file which can be done using Relog and I tested it but in some cases it fails with this error
2. Has Microsoft documented the error codes with which Relog fails.? How can I handle the possible cases of failure.?
3. Unrelated questions: Can Relog join more than 30 files together to one single merged Performance file.
 I found online at some places that Relog had a limitation that it cannot merge more than 32 separate performance file to one single performance file.

I suggested to use Relog but Relog has been disappointing so far with a lot of unknown errors. A detailed documentation of the error codes in not provided by Microsoft.

Finding answers to som... Read more

Read other answers
RELEVANCY SCORE 54.4

Hi,

Recently, I'm having slow file loading while opening ms word files and excel files directly from windows explorer. It takes a minute to load, however it opens immediately if I open .doc files or .xls files directly from their application software. It also take a minute for MS Word and Excel software to shut down.

I have run my antivirus (Symantec) and MBAM but they all show no virus was found. I'm not sure what should I do next, please advice.

A:Microsoft Word & Excel - problem with opening files in Word and Excel

What version of Word & Excel?

Read other 6 answers
RELEVANCY SCORE 50.8

The only way I can get any MS office programs to open is to right click and choose the "open with" option. I check the box to Use as default, but they still won't open the next time.
I tried run > winword /r to reset word, but that didn't help either.
All the icons are the same, a little blue chemistry beaker.
In properties, the type of files say they are, "FFV files (docx), FFV files (xlsx), etc".
How do I get these files to open the normal double click way?

A:Excel and Word files will not open in Excel and Word

Have you tried repairing the Office installation (via Start > Windows Control Panel > Programs > Programs & Features > Microsoft Office (version) > Change > Repair)?

Aside from that if the file types are "FFV files (docx), FFV files (xlsx), etc", that suggests you've installed some other software that has taken over the file associations. In that case, you might consider uninstalling that software; otherwise you'll need to reset the file associations, by right-clicking each Office file-type (docx, xlsx, etc.) and using Open With>Choose default program to re-associate them with the correct Office application.

Read other 1 answers
RELEVANCY SCORE 48.4

I'm working on a Bill of Material creation automation project that requires some expertise in VBA, and I have none.
The objective is to run a macro from an excel spreadsheet called "PGE BOM", to do the following:
1) Go to the folder "C:\Documents and Settings\Desktop\Auto Project"
2) Find all the .mdb databases in this folder
3) Find "HistoricalMaterialItemsAll" table in EACH of those databases in step 2, and import the data from the columns listed below into PGE BOM.xls's columns C through G:
DrawingNumber
ItemNumber
Quantity
PgeCode
Description
The following is a VBA code that my friend had written in Excel 2007. Unfortunately I have an older version (2000) and the code does not seem to be compatible with Excel 2000.
Sub ImportAccessData()
Stop
dPath = "C:\Documents and Settings\Desktop\Auto Project\"
sFile = "*.MDB"
strSrch = dPath & sFile
Set TargetWB = Application.ActiveWorkbook
Set TargetWS = TargetWB.ActiveSheet
sRow = 2
bFile = False
If Dir(strSrch) <> "" Then
strFlNm = Dir(strSrch)
bFile = True
End If
Do Until bFile = False
strPath = dPath & strFlNm
Call GetData(strPath)
strFlNm = Dir
If strFlNm = "" Then bFile = False
Loop
End Sub
Sub GetData(fl)
Stop
strSQL = "Select HistoricalMaterialItemsAll.* From HistoricalMaterialItemsAll"
Workbooks.OpenDatabase fl, strSQL, xlCmdTable
Set WB = Application.ActiveWorkbook
Set WS = Applicatio... Read more

A:Excel Macro - VBA code to import access data to excel

Hello, and welcome to the board!

When posting code, please use CODE tags, which extremely helps with readability.

Perhaps you could try using the code constant???...
Code:

Option Explicit

Sub ImportAccessData()
Dim dPath As String, sFile As String, strSrch As String
Dim TargetWB As Workbook, TargetWS As Worksheet
Dim sRow As Long, bFile As Boolean, strFlNm As String, strPath As String
dPath = "C:\Documents and Settings\Desktop\Auto Project\"
sFile = "*.MDB"
strSrch = dPath & sFile
sRow = 2
bFile = False
Set TargetWB = Application.ActiveWorkbook
Set TargetWS = TargetWB.ActiveSheet
If Dir(strSrch) <> "" Then
strFlNm = Dir(strSrch)
bFile = True
End If
Do Until bFile = False
strPath = dPath & strFlNm
Call GetData(strPath, TargetWB, TargetWS)
strFlNm = Dir()
If strFlNm = "" Then bFile = False
Loop
End Sub

Sub GetData(fl As String, WB As Workbook, ws As Worksheet)
Dim strSQL As String, iRow As Long, sRow As Long
strSQL = "SELECT HistoricalMaterialItemsAll.* FROM HistoricalMaterialItemsAll"
Workbooks.OpenDatabase fl, strSQL, 3 'xlCmdTable
iRow = 2
Do Until ws.Cells(iRow, 1) = ""
ws.Cells(sRow, 7) = ws.Cells(iRow, 5) 'Get the Description
iRow = iRow + 1
sRow = sRow + 1
Loop
Application.DisplayAlerts = False
WB.... Read more

Read other 1 answers
RELEVANCY SCORE 48.4

Firstly I am a beginner of beginners but I try to learn as much as I can.
I have put the following protection code into an Excel 2003 workbook and everything runs ok. I then opened the workbook in Excel 2007, and saved it as a .xlsm file. When I try to open the .xlsm file in Excel 2007, I get a vba Runtime error 13, "Type mismatch", and the code sticks at the first line below("If Worksheets...). I have tried everything that my limited knowledge allows, searched the web for 2 days, and still have no answers.
Any help would be greatly appreciated.

Private Sub Workbook_Open()
If Worksheets(28).[A51] > "" And Worksheets(28).[A50] = Worksheets(28).[A51] = False Then
MsgBox "Sorry, this program is not registered for this computer, please e-mail .......... for more info."
Application.DisplayAlerts = False
Application.Quit
End If
End Sub
My system specs are shown below.

Tech Support Guy System Info Utility version 1.0.0.2
OS Version: Microsoft Windows 7 Home Premium, Service Pack 1, 64 bit
Processor: Intel(R) Core(TM) i3 CPU M 380 @ 2.53GHz, Intel64 Family 6 Model 37 Stepping 5
Processor Count: 4
RAM: 2934 Mb
Graphics Card: Intel(R) HD Graphics, 1243 Mb
Hard Drives: C: Total - 290143 MB, Free - 172186 MB;
Motherboard: Dell Inc., 0WXY9J
Antivirus: avast! Antivirus, Updated and Enabled
 

A:Solved: Excel 2003 vba code not working in Excel 2007

Read other 16 answers
RELEVANCY SCORE 48

Hello all,

I have been presented with a project that involves Forms that I am not able
to resolve.

Basically I have been asked to create a document template where other team
members can fill out a form that asks a series of questions, then to have
only the completed form results export to a new file.

I am aware that Word can export the form results to a text file, but when I
do this all of the questions that were on the original form are exported to
the new file.

What we are looking to achieve in the end:
If the end user is faced with 20 questions, but only 12 of the questions
pertain to the end users project, only the 12 completed form fields will
export to a new file.

I know that this should be possible with using a macro button to export the data, but that is where I need the help.

I tried searching for this exact situation, but I did not find any matches, hence the new thread.

Thank you in advance,

Bill
 

A:Macro help needed to export Word form results to a new file... Word/Excel

Read other 11 answers
RELEVANCY SCORE 47.6

Hello again,

I have a word doc that has a form in it. The form may have any number of fields (boxes) to type text answers into, or be a drop down list to select an answer from. I need an excel macro that extracts all data from the form, but with every five fields starting a new row in excel. So all data from the form will appear within 5 columns in an excel spreadsheet.

field 1 field 2 field 3 field 4 field 5
field 6 field 7 field 8 field 9 field 10
etc

Is that possible? I have had no luck to do it myself.

Sample form attached, thank you
____________________________
 

A:Solved: Excel macro to extract Word form data into Excel

Read other 7 answers
RELEVANCY SCORE 47.6

I have an Excel Workbook where I try to embed a Word and Excel file (icon). But, I cannot open the file afterwards. However, my colleagues can open it when I sent it to them by email. What could be the problem with my application.

I tried disabling my spyware software and reloading Microsoft Office XP but the problem is still there,

What could be the problem?
Thanks a lot
 

Read other answers
RELEVANCY SCORE 47.2

I run a weekly excel 2007 macro that converts a spreadsheet to a Word document, but it stops after row 29 of data. Any spreadsheet with 29 rows or less works fine. If I have 34 rows of data, the macro hangs. See below for script. Any help would be appreciated.

Public Sub AddControls(WrdApp As Word.Application, CurRow As Integer)
Dim OptChecked As Boolean
Dim GrpName As String
GrpName = "Grp" & CurRow
'Calculate the colors based on the cell information.
CurRange = "F" & CurRow & ".." & "F" & CurRow
Range(CurRange).Select

If InStr(1, UCase(ActiveCell.Text), "X SRM") > 0 Then 'SRM
OptChecked = True
Else
OptChecked = False
End If

SetCellBG WrdApp, True
WrdApp.Selection.TypeText Text:="Governance:" & vbCrLf

Set RadioObj = WrdApp.Selection.InlineShapes.AddOLEControl("Forms.OptionButton.1")
With RadioObj.OLEFormat.Object
.GroupName = GrpName
.Caption = "SRM"
.Font.Name = "Arial"
.Font.Size = 8
.Value = OptChecked
End With

If InStr(1, UCase(ActiveCell.Text), "X PPO") > 0 Then ' PPO
OptChecked = True
Else
OptChecked = False
End If

WrdApp.Selection.Collapse Direction:=wdCollapseEnd
WrdApp.Selection.TypeParagraph

Set RadioObj = WrdApp.Selection.InlineShapes.AddOLEControl("Forms.OptionButton.1")
With RadioObj.OLEFormat.Object
.GroupName = GrpName
.Caption = "PPO"
.Font.Name = "Arial"
.Font.Size = 8
.Value = O... Read more

A:Excel Macro - converting excel to word doc - stops after row 29

Read other 13 answers
RELEVANCY SCORE 47.2

Hi
I am trying to export data from word or excel form into a spreadsheet. I have tried the macro at http://forums.techguy.org/business-applications/257309-exporting-word-form-data-excel.html and it worked for all text fields but not the drop down list options that I have in my form. Can anyone please help/

I have never done this before, hence the struggle. Any help would be much appreciated.

I attach the word form and the excel form which also includes the excel spreadsheet that will collate the data for analysis.

I would prefer the form in word and have it set up as that indicated in the forum thread above but picking up the data from the drop down lists as well.

Thanks
LAD786
 

A:Export data from word or excel into Excel spreadsheet

Hi there, welcome to the forum.
It seems this post you added on August 12th hasn't given you much answers.
You mention the two files, OK, But what I don't understand
I am trying to export data from word or excel form into a spreadsheet. ...
Click to expand...

You probably forgot to attach the macro's with it, that is if you did anything with the link you mentioned.
If you could attach the files with the macros, I could take a look and see what I can do for you.

Another thinng From Word or Excel.

Which one is it going to be?
 

Read other 1 answers
RELEVANCY SCORE 46.4

I wish to Fully automate the following manual process that is already in place. ie I cant go using access.
Currently we manually type up an "Authority to Work" (ATW) that has to be uniquely numbered for ISO 9000 purposes. As part of this ATW the following fields have to be captured/ registered.
The user who is filling in the form, a short description of work ("Clean sample panels"), and the date that the ATW is raised.
Currently we print out a blank template of the ATW and hand write in all of the above fields plus a number of other fields that for the purpose of this exercise arn't important.
We then open up an existing Excel worksheet on a network drive (important) look at the next available empty cell in the first column add 1 to the previous cell and type this in as the next ATW number. We type in the users name and the description of the work and the date the ATW was created. Save the worksheet.
Go back to the printed out template and add the unigue number into a box of the form..

My idea is to make an electronic form to be filled in in Word then make the whole of the above process automatic to be triggered by the action of going to File Print in Word. The ATW still needs to be printed out as it requires to have signatures on it.
Any help appreciated.
 

Read other answers
RELEVANCY SCORE 46.4

We have got a problem at work with excel 2007, we share documents over our network so that everyone can get to them when they need to. But, at the min we have a problem where when somebody opens an excel file edit it and then save and close it nobody else (including the user that changed it) can open the file and edit it. they can olny see it in read only mode.

This is getting really annoying and after reading people comments on the web i have found that this is something that is happening to a number of people.

I have read about a setting in Word which is "Copy remotely stored files onto your computer, and update the remote file when saving"

This setting is not listed in Excel's settings, is there a way of making excel work in this way?

All help will be great, this problem is getting really annoying because we have to keep restarting the computers.

thanks

JPLamb
 

A:Excel 2007:Function in Word is it in Excel?

Hiya, there are a couple of things you can try to see if they are affecting the issue you are having.

Firstly
Double check the Spreadsheet properties to make sure that they are not becoming readonly when saved. Right Click on on doc in Windows Explorer and click Properties, make sure read only is not ticked.
Secondly check the setting in the area highlighted in xl2, especially the share workbook. It may be that for some reason it thinks someone still has the spreadsheet open.
Thirdly try the option in xl3

Let me know how you get on.
 

Read other 2 answers
RELEVANCY SCORE 44.4

Hey all,

I have come to you in a fit of desperation. My USB drive was stolen recently and my master Excel data file was lost, which contained all my compiled data from my most recent lab experiment.

Anyway, I have charts of all the important stuff in a word document. The data is there, I can hover on each data point and see the values, and the axes and chart are all accessible for editing.

My question is, how the heck do I extract that data back out of the chart into a table or Excel spreadsheet? There MUST be a way that is better than copying down each data point one at a time

Your help is greatly appreciated.
 

A:Excel chart in Word 2010: extract chart values? Lost Excel data file!!!! Help.

Hi welcome to the fourm.
I don't know it reverse engineering is possible.
Something like convert chart to table?

One thing you could try is copy the chart back to a new Excel file and see if more is possible there than in Word?

Like I said never needed this. Have you googled for something like Excel data reverse enginieering?
Maybe something come up.
 

Read other 1 answers
RELEVANCY SCORE 43.2

Hello I found an answer to this question but it was specific to his form. I have several Excel Logs (Tables) that contain information that is also entered into a separate form. Some forms are in excel and some are in word. I would like to hit a button that transfers a row of data to the form so i only have t enter data once. The forms will have additional information that will be entered. The forms are saved as a specific file type and are also printed so the answer that i found on this site may work but it puts the data into a different spread sheet in the same workbook and i need to send the data to a new workbook and in one case to a word doc. Can someone help me out. I have attached a couple examples of what i currently do.

Thanks for the help
 

A:Solved: Populate Excel Form and Word Form from Excel Table

Read other 16 answers
RELEVANCY SCORE 42.4

I have created the following code to print & save a copy of a document. The code works fine on the computer I created it on, but I can not get it to work on other computers. I have even emailed the doc and tried to use it from the copy - the code hangs up on 'Date'

Sub Macro4()
'
' Macro4 Macro
' Macro recorded 7/25/2008 by jwevans
'
Dim strfilename As String
strfilename = "\\blank.net\blank\blank\TZPRShare$\SHIFT TURNOVER\Work Message Archive\" & Format(Date, "mmm-dd-yy") & "_" & Format(Time, "hh-mm-ss") & ".doc"
ActiveDocument.PrintOut
ActiveDocument.SaveAs FileName:=strfilename, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
End Sub
 

A:Word VBA code

You might try

Code:
Format$(Date, "mmm-dd-yy")
instead and force it to be string.
 

Read other 2 answers
RELEVANCY SCORE 42.4

Good Morning.
I'm trying to write VB code for Excel in a workbook that tracks vacation time accrued and used. Each line is for an employee, with hire date, latest anniversary date, vacation due (from a lookup table based on years worked), vacation time used, and balance (and a couple other insignificant items).

I want the user to select the row for an employee who has passed his anniversary date and execute code to do the following:

Erase all the vacation time recorded accross the column (month by month), and roll the anniversary date one year forward. This is the part I'm having trouble with. What would be the code to take a date and add one year. This is sometimes 365 days and sometimes 366, and and it isn't based on "now", its based on the span of time from the current anniversary to the next anniversary that I'm updating to. I've tried to build some tables, but there are too many variations.

Any ideas?
Thanks.
 

A:Excel VB Code

Read other 6 answers
RELEVANCY SCORE 42.4

I would like to know or get help with the VBA coding to do the following if possible, I have an excel sheet with file links (link in column (I) link text in column (J)) there are e-mail addresses in Column (H) and required dates in column (D).
I would like to know if the dates can be compared (today) for out of date occurrences and dates approaching 31 days of the date in column (D) (older than (=TODAY()+31)) a possibility would be to ask for user defined input on the dates after today (31) in the example above.
In this event the sheet could be filtered to show all columns and only those rows with the dates meeting the criteria, which would then raise an email (Outlook) to be viewed prior to sending and attach the files (column (I) or (J))
One e-mail to one recipient but multiple files if there are any?
From: (me)
To: (I will add a column with the recipientís name) letís say (L)
CC : (someone)
BCC: (someone else)
Subject: ďtextĒ + cells in column (C) relative to all the date occurrences to the recipient in column (H)

Body text
((Name in Column (L))

Text 1
Text 2
Text 3

A sample file is attached with arbitrary information

Many thanks in appreciation
 

A:Excel Code Help

I note a few views, and can appreciate its a lengthily request, I am trying to refresh my coding as it has been nearing 20 years since doing anything.

But I have made a start; Button calls on macro to get the date and append it with user input to advance the filter criteria, and then creates a new sheet with the date of the filter.
Code:
Sub In_Progress()
Dim vData
Dim firstDate As Date, secondDate As Date
Dim ActNm As String
'Dim LastColumn As Long
On Error Resume Next
Application.DisplayAlerts = False
vData = Application.InputBox _
(Prompt:="Please select a single cell housing the number, " _
& "or enter the number directly.", _
Title:="Days from Today", Type:=1 + 8)
On Error GoTo 0
Application.DisplayAlerts = True
If IsNumeric(vData) And vData <> 0 Then

firstDate = DateValue(Now)
secondDate = DateAdd("d", vData, firstDate)
'test date increment by user input
MsgBox secondDate

With ActiveWorkbook.Sheets

.Add after:=Worksheets("ALL - cals")

End With

ActNm = ActiveSheet.Name

On Error Resume Next

ActiveSheet.Name = "due - cals " & Format(secondDate, "mm-dd-yy")

NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name... Read more

Read other 3 answers
RELEVANCY SCORE 42.4

Hi, I'm new to this forum.
I was looking for different dialog options and VBA code for my Excel sheets when I came upon the Printer.Dlg code where you can choose the sheet you want to print.
I have altered the code in such a manner that you can use the checkboxes to select one or more items from a specific range in any sheet and whereever it is located.
If there is anyone intersetd I will post it.
What is does is you call the function giving the sheetname, column letter, starting rownumber and endding rownumber:
Call SelectFromList("Sheet3", "D" , 5, 25)
This will result in a Dialog screen with a list of 20 values in the range which you can select and then write that part of the code you need that does something with this.
The code allows any number of rows, The max per dialog screen is 200 spread over 4 columns of 50.
It was fun to do.
I am beginning to like VBA routines in my Excel sheets thus permitting users to enter only that data which is requested of making only the permitted selections.

Thanks for the attention.

Cheers,

Hans
 

A:VBA code for Excel

Hi, since you started this, please do post your code so if someone else comes looking for such a solution they can find it.
I would suggest that you check out this site also - it's a great place for coders and several of the other who post here regularly also haunt it (in fact, one of the people who manages it, who goes by firefytr, is also a regular here)
http://www.vbaexpress.com/forum/index.php
 

Read other 2 answers
RELEVANCY SCORE 42.4

Code:
Sub Data()
'
' SummarySheet Macro
' Macro recorded 2/12/2009
' Create links to all sheets and show totals
'
Dim WS As Worksheet
Dim wsANm As String
Dim wsA As Worksheet
Dim r As Integer
Dim MyTot1 As Variant
Dim MyTot2 As Variant
Dim MyTot3 As Variant
Dim MyTot4 As Variant
Dim MyTot5 As Variant
Dim MyTot6 As Variant
Dim MyTot7 As Variant
Dim MyTot8 As Variant
Dim MyTot9 As Variant
' Cell that has the totals on each sheet
Set MyTot1 = Range("c7")
Set MyTot2 = Range("c6")
Set MyTot3 = Range("C11")
Set MyTot4 = Range("e11")
Set MyTot5 = Range("g11")
Set MyTot6 = Range("B4")
Set MyTot7 = Range("D8")
Set MyTot8 = Range("K2")
Set MyTot9 = Range("L2")

'
Set wsA = Worksheets.Add(Before:=Worksheets(1))
MyTot1 = MyTot1.Address
MyTot2 = MyTot2.Address
MyTot3 = MyTot3.Address
MyTot4 = MyTot4.Address
MyTot5 = MyTot5.Address
MyTot6 = MyTot6.Address
MyTot7 = MyTot7.Address
MyTot8 = MyTot8.Address
MyTot9 = MyTot9.Address
wsANm = wsA.Name
On Error Resume Next
wsA.Name = "Data"
NoName: If Err.Number = 1004 Then
Application.DisplayAlerts = False
Sheets("Data").Cells.Clear
'Sheets.Add.Name = "Data"
'Application.DisplayAlerts = True
'wsA.Name = "Data"
'End If
'If wsA.Name = wsANm Then GoTo NoName
On Error GoTo 0
'
r = wsA.Range("B65536").End(xlUp).Row + 1
wsA.Cells(r + -1, 1).Value = "Date#"
wsA.Cells(r + -1, 1).Font.Italic = True
wsA.Cells(r... Read more

Read other answers
RELEVANCY SCORE 42

I would like to see the code that Microsoft put behind one of thier buttons in Microsoft Word 2000. How can I see the code for Word? Thanks.
 

A:Microsoft Word Code

Read other 7 answers
RELEVANCY SCORE 42

i just got a new hp notebook and while using pre-installed MS WORD it keeps asking for a product key code.  where can i find it?  i checked the notebook, paper work, battery compartment, etc.  should i have to do this on factory installed software? thanks

Read other answers
RELEVANCY SCORE 42

Hi.

Im trying to "grap" the filename and path of "doc 1" and paste the contents of "doc 1" into "doc2" then close "doc 1" save the file with the path and filename information from "doc 1".

Is this possible?

Jon
 

A:VB Macro code for Word

Read other 7 answers
RELEVANCY SCORE 42

With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = True
.Execute FindText:="Inc aa", _
ReplaceWith:="incorporated", Replace:=wdReplaceAll
End With

if my document contains below line of code
inc aa for the inc aabcde and the inc aa

the above code will replace inc aabcde also

is this a bug in ms word
 

A:Problem with code in Word

Read other 13 answers
RELEVANCY SCORE 42

The following code works on one computer but not another :
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 7/25/2008 by jwevans
'
Dim strfilename As String
strfilename = "\\blank.net\blank\blank\TZPRShare$\SHIFT TURNOVER\Work Message Archive\" & Format(Date, "mmm-dd-yy") & "_" & Format(Time, "hh-mm-ss") & ".doc"
ActiveDocument.PrintOut
ActiveDocument.SaveAs FileName:=strfilename, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
End Sub
 

A:Solved: Word VBA code

Read other 16 answers
RELEVANCY SCORE 42

Hi There

Can anyone help???

I have written a macro to split a mail merge document into individual letters. It works OK and does what it is meant to do.

I have also been able to set the address lines and references lines to different font style (Trebuchet ms size 10). BUT

The main body of the letter after i have split the maile merge changes to the word default!!! quite annoying...

Does anyone have any type of answer or vba code to stop this doing it?

Steve
 

A:VBA Code for ms word 2010

Please post all of your existing code.

Rollin
 

Read other 2 answers
RELEVANCY SCORE 42

Hi Guys,
I posted this earlier to another section but it may be better suited to here.
Without going into too many details at this stage we have a web application that has an object embedded into one of the pages. This object has been built using VB.NET and basically it talks to a 3rd party application to get some data into a datagrid. This is not a problem. The user selects an entry from the grid and the application opens Word and triggers an addin (written in VB.NET) which then goes off and opens a specific Word document. The system is a bit more complicated than that but the point is all this works really well. The problem is that sometimes (well too often really) a user will make the selection and the document will open but Word has no menus or toolbars visible and there appears to be no way of getting them to show as there are no menus whatsoever to use. It is like the document is being shown in a picture window. The only way to resolve this situation is for the user to shut down word and try again.
Unfortunately it may take several goes until it works properly. The question is, does anybody know why this is happening and how do I stop it happening.
 

A:Opening Word from code

Read other 7 answers
RELEVANCY SCORE 42

My activation code is not working. How do can I access my word folders if I cant get in?

A:word activation code

Call MS and get the activation straightened out
Or use OpenOffice.org

Read other 1 answers
RELEVANCY SCORE 42

Hi,
i have a word document that has this in it "I, Student Name" and i am trying to write a code so when the user closes it a inputbox comes up and ask the user to enter their name for example i put Bob smith in it and it replaces Student name with bob smith and then closes but when i open it again it has bob smith which is right but when i close it,
it asks for the name again how can i make it so it doesnt ask for the name again when its already there?

the code i have is

Code:
Private Sub Document_Close()
Dim rng As Range
Set rng = ThisDocument.Content
rng.Find.Execute "student name", False, , , , , , , , InputBox("Enter Your Name"), wdReplaceAll
ThisDocument.Save
End Sub
 

A:Solved: Word VBA Code Help

Read other 7 answers
RELEVANCY SCORE 42

Good Morning
I'm trying to build a nice data entry form in Excel. Has 5 required fields, the first 2 of which should default to name and todays date - which is at the top of the spreadsheet. I have 5 buttons: Next, Previous, Add, Delete, Close. I'm working on the code for those. But in the meantime, I'm hung up on the following problem:

Some code that I have written keeps taking Name out of the spreadsheet cell A1. I can understand how that can happen when I run the form's code. But now when the form is closed, and I try to type the name back into A1, it will not stay. When I hit enter, it just disappears, not even in the formula bar. I've checked the formatting and nothing is odd there. If I insert a new row 1, the old row (now 2) works, and the new row 1 still has disappearing text. So something in my code is telling it to blank out cell A1. I don't understand how that can happen if I don't even run the code?

The following is all the code behind the form. The only other code in the project is a button click on sheet one. The only code directly referring to Cell A1, is at the very bottom with the A1 reference bolded. Thanks for your help.
-----------------------------------------------------------

Dim CurrentRow As Long

Private Sub cmdAdd_Click()
' Save form contents before changing rows:
SaveRow
' If list is empty start in row 5:
If Cells(5, 1).Value = "" Then
CurrentRow = 1
' Set current row to first empty r... Read more

A:Excel Code for a form

I have tried recreating the problem that you describe but with no success.
What version of Excel are you using?
Can you post the file? It would save others having to recreate the form.

I think I found a bug in your code.

In cmdAdd_Click and UserForm_Activate I think that the following line:
CurrentRow = 1
needs to be changed to
CurrentRow = 5
given your comments in the code.

Is there any other information that you can give?
 

Read other 3 answers
RELEVANCY SCORE 42

I have several checkboxes on Sheet1 that populates Sheet2; if the checkbox = true. Depending on the ďtextĒ of A# on Sheet2, then a listbox will populate cell D# on Sheet 2.

The problem Iím having is that I want the screen to stay on Sheet1 as the user clicks on the checkboxes. With the code Iím using, Iím receiving errors.

Private Sub CheckBox36_Click()
If CheckBox36.Value = True Then
Worksheets("Sheet2").Range("A6").Value = "Air Emissions"
Worksheets("Sheet2").Range("B6").Value = "Point Source Air Emission"
Worksheets("Sheet2").Range("C6").Value = "NOX"
Else
Worksheets("Sheet2").Range("B6").ClearContents
End If
If Worksheets("Sheet2").Range("A6").Value = "Air Emissions" Then
Worksheets("Sheet2").Range("D6").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=AirEmissionsI"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End
End If
End Sub

Using the code above, I receive the "Select Method of Range Class Failed"; debug in red

So I tried this below (changes in blue)

Private Sub CheckBox9_Click()
Dim n As Range
Set n = Sheets("Sheet2").[d5]
If CheckBo... Read more

A:Excel 2002 VB Code Help

I don't do that much programming in Excel, but I'm really familiar with VBA, so I'll take a shot. Seems like you have two possibilities:

1. turn off Echo (the screen updater, check out Excel help if you don't know it), and make Sheet2 the active sheet, carry out the stuff, and make Sheet1 the active sheet, and turn Echo back on. The user will see nothing. I'm not sure if your problem is caused by the fact that the sheet is inactive.

2. name the range you're trying to activate, in your second code example. Then you should be able to set your variable to Worksheets("Sheet2").Ranges("NameOfYourRangeHere"), without too much trouble.

If none of this works, and no one else has a better idea, I can dig into my Excel code archives and see what I can come up with.

kls is gonna rock you. hehe.
 

Read other 3 answers
RELEVANCY SCORE 42

Hi again
I'm struggling with a code.
What I want the code to do is the following

If ActiveCell = any number from 1 to 200 then
code goes here

In other words I want to replace this code
If ActiveCell = 1 or 2 or 3 or 4.....or 200 then
code goes here

with a shorter code if possible
Thanks
 

A:Need help with one line of code in Excel

if I understand you correctly you want something like
Code:
If ActiveCell.Value >= 1 And ActiveCell.Value <= 200 Then
Debug.Print "oh yeah"
End If

 

Read other 3 answers
RELEVANCY SCORE 42

Hi,

I'm trying to set up a Question and Answer form where different things occur depending on what the answer is. I have two buttons - "Yes" and "No".
My sheets are "Guide", "Segments" and "Receipt".

The questions are on "Guide".

If "Yes" is selected I want Cell E3 on "Guide" to be copied to Cell C31 on "Receipt"

If "No" is selected I want Cell F3 on "Guide" to be copied on Cell C31 on "Receipt" and Cell A3 on "Guide" to be copied to Cell H4 on "Segments".

There are mulitple questions, but once I have the basics of how to do this I am happy that I could replicate this for the rest of my questions.

Many thanks.
 

A:Excel Button Code

Hi,
Will it always be Cell E3 on Guide -> C31 in Receipt and F3 and the other ones too?

And not less important, which version of Excel are you using?
 

Read other 2 answers
RELEVANCY SCORE 42

Hi I am getting weird exception and I dont understand why, I been struggling and no luck

When I load (download) an excel file with macro from a server to my desktop and open it
I get the below error message:

Run-time error '1004':
Unable to get the CheckBoxes property of the Worksheet clas

I noticed if I open and click save, close and open again the error is not there anymore.

Why is the error gone? I am not changing anything in the file, just save and open again.

Thank you for your help
 

A:Solved: Excel VBA code

It may be that the code is refering to a named object, which can only be in such state when saved rather than being opened from temp location.
 

Read other 1 answers
RELEVANCY SCORE 42

OK, i want to have multiple checkboxes adding values to range(B42:B60) but i have two
big problems. First, i want to make the value disappear if the corresponding checkbox is unchecked.
Second, for some reasons i can not make the check boxes add values beyond the fist one/two rows of column B. I did it before when i was testing the code(blank sheet) but now on the real project(lots of values) it doesnt work.
Below is the code. I dont remember doing anything different to it when i was testing it.

See if you can help me. Thanks.

Private Sub CheckBox1_Click()
If CheckBox1 = True Then

Dim NextCell As Range
'Set NextCell to last unavailable cell beyond D4 (next cell is available)
Set NextCell = Sheet1.Range("B42").End(xlDown)
'Quit if no place to put value (next available cell is beyond row 20)
If NextCell.Row < 32000 And NextCell.Row > 29 Then Exit Sub
If NextCell.Row > 32000 Then Set NextCell = Range("B42")

NextCell.Offset(1).Value = "Thank you for choosing our services. We appreciate your business."

End If

End Sub
 

Read other answers
RELEVANCY SCORE 42

This is the what I want to happen...

ActiveWorkbook.SaveAs Filename:=Range("B1").Value
The code will read the value in B1 and make that the saveas file name.

How do I do this??
Thank you.
 

A:how to insert VBA code with Excel

Tools -- Macro -- Record. Make sure you store in This Workbook. Click OK. Stop Recording (click the black square on Stop Recording toolbar).

Press ALT+F8. Highlight the macro name, click Edit.

Replace everything between the "Sub ..." and "End Sub" lines with your code. Close the Visual Basic Editor.

NB - your code will crash if whatever's in B1 isn't a valid filename.

Rgds,
Andy
 

Read other 1 answers
RELEVANCY SCORE 42

i have studied VB back in university time like 8 years ago! now im getting hints and tips from the net to find my way: i have found the below code and it works perfectly now i need to add another code to copy anything inside the range of sheet 1 to sheet2 and sheet 3 with timestamp whenever i run the macros (like activity log), pleeeease!

Sub Mail_Range_Outlook_Body()
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2010
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

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

Set rng = Nothing
On Error Resume Next
Set rng = Sheets("").Range("B2:J5").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

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.HTMLBody = RangetoHTML(rng)
.Display 'or use .Send
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 

A:Excel Macros Code

am i at the right category to post that? sorry im new
 

Read other 3 answers
RELEVANCY SCORE 42

hi, below is the vb code added to most of the worksheets in a work book; this code is not working now;
history...this code was working...then i realized that i could have the same code apply to all worksheets in the work book, so i deleted the recently applied code for each worksheet and implemented the code for the work book level; unfortunately, there were a few worksheets at the end of the workbook that were not the same format as the others and this code afftected results in those worksheets; after realizing this, i deleted the code that worked at the workbook level and then added the origional code back to each worksheet. what do i need to do to make this code work now?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("c4").Value < Range("c19").Value Then
Range("c4").Value = Range("c19").Value
End If
End Sub
 

A:excel 2010-vb code help

Hi there,

The code below when it's in a VBAProject module will go through all the worksheets and test C4 agains C19
Code:

Sub ChangeC4()
Dim ws as Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Range("c4").Value < ws.Range("c19").Value Then
ws.Range("c4").Value = ws.Range("c19").Value
End If
Next ws
End Sub

However, if not all worksheets are the saem format and this does not apply, then you will need to include a test verifying that the worksheet is one of the range where change applies to

The If statement will have to come in the redline below

and the End If statement at the second red line of code
Code:

Sub ChangeC4()
Dim ws as Worksheet
For Each ws In ThisWorkbook.Worksheets
[COLOR="Red"]< Here must come an If statement testing the worksheet>[/COLOR]
If ws.Range("c4").Value < ws.Range("c19").Value Then
ws.Range("c4").Value = ws.Range("c19").Value
End If
[COLOR="red"]< And here the end if >[/COLOR]
Next ws
End Sub

It's bed-time here so I'm off-line
 

Read other 1 answers
RELEVANCY SCORE 42

I am trying to set up a Excel file which will prompt the operator enter the lowest and higest cell row number which is needed and then will perform several operations using the data within the slected region.

example of what I want: I have 1 columns and 100 rows and I only need to take the average of each column on row 40 to row 50.

So the program ask me to enter in the lowest row, and the hightest row and takes an average in that region.

I now want to analys rows 60 to 70 with out changing the code.

How would I go about writing such a file in excel
 

A:Excel code question

Read other 7 answers
RELEVANCY SCORE 42

I have developed a small database in excel which utilizes a UserForm to collect information for new database entries. I have only limited understanding of VBA programming, so I need a little help on the code to perform the following function.

After I type in all the required fields in my UserForm, what code do I need to insert in order for the new entries to be inserted in the first empty row of the database? I know how to set the value of a cell to the data in the UserForm, but I'm not sure how to make the computer start from the top of the database and move downward until it finds an empty row, and then insert the entered data into the row.

Any help would be greatly appreciated!

Thanks
 

A:Solved: Excel VBA Code Help

Read other 9 answers
RELEVANCY SCORE 42

I'm writing a macro in Excel 2007 and would like the macro to pause for user input and then search for the word input by the user.

Any suggestions would be appreciated.

Thanks.
 

A:Excel VBA Code Question

The easiest way to do this is to prompt the user with an inputbox. Can you post your existing macro code for us to look at?

Regards,
Rollin
 

Read other 2 answers
RELEVANCY SCORE 42

Hello

I made a VBA code for my excel to automatically send email and it is giving error when I run it. Please can any one please check what am i doing wrong here.

Following is my VB code

Sub Mail_with_outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strto = Cells(FormulaCell.Row, "M").Value
strcc = ""
strbcc = ""
strsub = "Your subject"
strbody = "Hi " & Cells(FormulaCell.Row, "L").Value & vbNewLine & vbNewLine & _
"Your total of this week is : " & Cells(FormulaCell.Row, "D").Value & _
vbNewLine & vbNewLine & "Good job"
With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Display ' or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Thanks in Advance
 

A:Please help in Excel VBA code problem

Problem coming in this coding is:

strto = Cells(FormulaCell.Row, "M").Value
and I dont know why.

Please can anyone help
 

Read other 2 answers
RELEVANCY SCORE 42

Can anyone help with why this error is appearing for the row of code below

Run-time erroe '424': Object required

ws.Cells(iRow, 1).Value = Me.txtJobName.Value

I have posted my whole code below what i am doing is using a userform to add new job name and job number to a separate workbook
Code:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim wb As Workbook
Set wb = Workbooks("Defined Name Lists.xls")
wb.Activate
Worksheets("JobName").Range("A2").Value = txtJobName.Text
'find first empty row in database

'check for a JobName
If Trim(Me.txtJobName.Value) = "" Then
Me.txtJobName.SetFocus
MsgBox "Please enter a Job Name"
Exit Sub

End If
'check for a JobNo
If Trim(Me.txtJobNo.Value) = "" Then
Me.txtJobNo.SetFocus
MsgBox "Please enter a Job No"
Exit Sub

End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtJobName.Value
ws.Cells(iRow, 2).Value = Me.txtJobNo.Value


If Me.txtJobNo.Value <> "" Then
Dim wbOutput As Workbook
Set wbOutput = Workbooks.Add
With wbOutput
.Title = "Job Number "
.Subject = "Job Number created " & Date
.Author = "Script generated"
.SaveAs Filename:=mydir & "\" & Me.txtJobNo.Value
End With
End If

'clear the data
Me.txtJobName.Value = ""
Me.txtJobNo.Value = ""
Me.txtJobNo.SetFocus
Exit Sub

End Sub
... Read more

A:Excel Code Problem

You have not Dim or Set the variable ws
 

Read other 3 answers
RELEVANCY SCORE 42

Sub GetData()
Application.ScreenUpdating = False
If ThisWorkbook.Sheets("Raw Data").Range("DD").Value = "YesData" Then
Worksheets("DD").Range("A1:Y100").Value = Worksheets("Raw Data").Range("A1:Y34").Value
End If

In the above code I am trying to populate another sheet "DD" with specific information from "Raw Data". In the If statement I want the data populated to only retrieve data rows from "RawData" that contains the word "YesData" in the D column.

Please help.
 

Read other answers